Right - the VB.Net spooler watch component is about 70% done but I am totally stuck on getting the DEVMODE structure as held in the pointer in JOB_INFO_2.
I keep getting the error:
I have the DEVMODE structure defined as a class thus:An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll
Additional information:
Can not marshal field DeviceMode of type PrinterQueueWatch.JOB_INFO_2:
The type definition of this field has no layout information.
and the JOB_INFO_2 defined thus:-Code:<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Friend Class DEVMODE <VBFixedString(32), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public pDeviceName As String 'CCHDEVICENAME Public dmSpecversion As Int16 Public dmSize As Int16 Public dmDriverExtra As Int16 Public dmFields As Int32 <MarshalAs(UnmanagedType.U2)> Public dmOrientation As PrintJob.DeviceOrientations <MarshalAs(UnmanagedType.U2)> Public dmPaperSize As PrintJob.PrinterPaperSizes Public dmPaperLength As Int16 Public dmPaperWidth As Int16 Public dmScale As Int16 Public dmCopies As Int16 Public dmDefaultSource As Int16 Public dmPrintQuality As Int16 <MarshalAs(UnmanagedType.U2)> Public dmColor As PrintJob.DeviceColourModes <MarshalAs(UnmanagedType.U2)> Public dmDuplex As PrintJob.DeviceDuplexSettings Public dmYResolution As Int16 Public dmTTOption As Int16 Public dmCollate As Int16 <VBFixedString(32), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public dmFormName As String Public dmUnusedPadding As Int16 Public dmBitsPerPel As Int16 Public dmPelsWidth As Int32 Public dmPelsHeight As Int32 Public dmDisplayFlags As Int32 Public dmDisplayFrequency As Int32 End Class
Any ideas what I have wrong here? I'm pretty sure the problem is in the DEVMODE class because if I return lpDevMode as an Int32, cast it to an IntPtr and useCode:<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _ Friend Class JOB_INFO_2 Public JobId As Int32 <MarshalAs(UnmanagedType.LPStr)> Public pPrinterName As String <MarshalAs(UnmanagedType.LPStr)> Public pMachineName As String <MarshalAs(UnmanagedType.LPStr)> Public pUserName As String <MarshalAs(UnmanagedType.LPStr)> Public pDocument As String <MarshalAs(UnmanagedType.LPStr)> Public pNotifyName As String <MarshalAs(UnmanagedType.LPStr)> Public pDatatype As String <MarshalAs(UnmanagedType.LPStr)> Public pPrintProcessor As String <MarshalAs(UnmanagedType.LPStr)> Public pParameters As String <MarshalAs(UnmanagedType.LPStr)> Public pDriverName As String <MarshalAs(UnmanagedType.LPStruct)> Public DeviceMode As DEVMODE <MarshalAs(UnmanagedType.LPStr)> Public pStatus As String <MarshalAs(UnmanagedType.U4)> Public Status As PrintJob.Print_Job_Statuses Public Priority As Int32 Public Position As Int32 Public TotalPage As Int32 Public PagesPrinted As Int32 <MarshalAs(UnmanagedType.Struct)> Public Submitted As SystemTime End Class
I get the same error.Code:Marshal.PtrToStructue(lpDevModePtr, dmThis)
Thanks in advance,
Duncan




Reply With Quote