Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

I'm using the FindFirstPrinterChangeNotification API call declared thus:-

<DllImport("winspool.drv", EntryPoint:="FindFirstPrinterChangeNotification", _
SetLastError:=True, CharSet:=CharSet.Ansi, _ 
ExactSpelling:=True, _ 
CallingConvention:=CallingConvention.StdCall)> _ 
Public Function FindFirstPrinterChangeNotification _ 
         (ByVal mhPrinter As Int32, _ 
          ByVal fwFlags As Int32, _ 
          ByVal fwOptions As Int32, _ 
          ByRef pPrintOptions As PRINTER_NOTIFY_OPTIONS ) As Int32
'\\ No code here ....
End Function

and the printer_notify _options thing is declared thus:-

 

<StructLayoiut(LayoutKind.Sequential> _ 
Public Structure PRINTER_NOTIFY_OPTIONS
    Dim dwVersion As Int32
    Dim dwFlags As Int32
    Dim Count As Int32
    <MarhalAs(UnmanagedType.LpStruct)> Dim pTypeJob As PRINTER_NOTIFY_OPTIONS_TYPE
End Structure

 

but when the code gets to the call it throws an exception "System.TypeLoadException" trying to pass a structure as an LPStruct.

 

"Additional information: Can not marshal field pType of type PRINTER_NOTIFY_OPTIONS: Marshalling types to LPStruct is not supported on structure fields"

 

I gather that the line:-

    <MarhalAs(UnmanagedType.LpStruct)> Dim pTypeJob As PRINTER_NOTIFY_OPTIONS_TYPE

is wrong - but how do I pass a pointer to a structure as a member of another structure to an API call?

 

Thanks in advance,

Duncan

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

My mistake - it wasn't a pointer-to-struct at all...should have been:

 

<StructLayout(LayoutKind.Sequential> _ 
Public Structure PRINTER_NOTIFY_OPTIONS
    Dim dwVersion As Int32
    Dim dwFlags As Int32
    Dim Count As Int32
    Dim pTypeJob As PRINTER_NOTIFY_OPTIONS_TYPE
End Structure

Printer Monitor for .NET? - see Merrion Computing Ltd for details
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...