*Experts* Merrion Posted November 19, 2002 *Experts* Posted November 19, 2002 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 Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Merrion Posted November 19, 2002 Author *Experts* Posted November 19, 2002 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 Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
Recommended Posts