System.TypeLoadException: Marshalling types to LPStruct is not supported on structure

Merrion

Well-known member
Joined
Sep 29, 2001
Messages
265
Location
Dublin, Ireland
User Rank
*Experts*
Im using the FindFirstPrinterChangeNotification API call declared thus:-
Code:
<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:-

Code:
<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:-
Code:
     <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
 
My mistake - it wasnt a pointer-to-struct at all...should have been:

Code:
<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
 
Back
Top