Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

The structure PRINTER_NOTIFY_OPTIONS_TYPE has a pointer to a variable length array of 16 bit integer flags as it's last member. In VB-Classic I filled this by using the VarPtr keyword....how do I go about doing this in VB.Net?

 

i.e.

Private Structure PRINTER_NOTIFY_OPTIONS_TYPE
    Dim wType As Int16
    Dim wReserved0 As Int16
    Dim dwReserved1 As Int32
    Dim dwReserved2 As Int32
    Dim Count As Int32 '\\Number of elements in the array
    Dim pFields As Int32 '\\Pointer to the array
End Type

 

which is populated....

Dim arTypes(0) As Int16 
arTypes(0) = Job_Notify_Indexes.JOB_NOTIFY_FIELD_STATUS

With pTypeJob
   .wType = Printer_Notification_Types.JOB_NOTIFY_TYPE
   .Count = 1
   '.pFields = ???? (was VarPtr(arTypes(0))
End With

 

Thanks in advance,

Duncan

Printer Monitor for .NET? - see Merrion Computing Ltd for details
  • *Experts*
Posted

**untested**`VarPtr equivalent

 

It may be possible thus:-

 

<StructLayout(LayoutKind.Sequential>_
Private Structure PRINTER_NOTIFY_OPTIONS_TYPE
  Dim wType As Int16
  Dim wReserved0 As Int16
  Dim dwReserved1 As Int32
  Dim dwReserved2 As Int32
  Dim Count As Int32
  <MarshalAs(UnmanagedType.LPArray)>Dim pFields() As Int16
End Structure

 

unfortunately I've a whole heap more converting of old VB6 code to go beforte I can test this out.

 

Thanks in advance,

Duncan

Printer Monitor for .NET? - see Merrion Computing Ltd for details
  • 4 weeks later...
  • *Experts*
Posted (edited)

You could try this (sorry, it's C# but should show what you need)

 

GCHandle p = GCHandle.Alloc(arTypes, GCHandleType.Pinned);
.pFields = p.AddrOfPinnedObject().ToInt32();
p.Free()

 

-ner

Edited by divil
"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...