Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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:

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.

 

I have the DEVMODE structure defined as a class thus:

<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

 

and the JOB_INFO_2 defined thus:-

<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

 

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 use

Marshal.PtrToStructue(lpDevModePtr, dmThis) 

I get the same error.

 

Thanks in advance,

Duncan

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

[PLAIN][Resolved] Getting DEVMODE from JOB_INFO_2[/PLAIN]

 

Sigh - often the case that as soon as you post something all over the internet you spot the obvious error. Anyway - the line:

<MarshalAs(UnmanagedType.U2)> Public dmOrientation As PrintJob.DeviceOrientations

Is not allowed because enumerated types are held as Int32 which is 4 bytes long.

Instead perform the type conversion explicityly thus:-

Private mdmOrientation As Int16
'...
Public ReadOnly Property dmOreintation() As PrintJob.DeviceOrientations
 Get
   Return CType(mdmOrientation, PrintJob.DeviceOrientations)
 End Get
End Property
'...

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...