|
-
March 22nd, 2003, 08:54 AM
#1
Marshalling error - getting DEVMODE from JOB_INFO_2
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:
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
and the JOB_INFO_2 defined thus:-
Code:
<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
Code:
Marshal.PtrToStructue(lpDevModePtr, dmThis)
I get the same error.
Thanks in advance,
Duncan
-
March 24th, 2003, 06:46 AM
#2
*Resolved*
My bad - i was marshalling an Int16 to an enumerated type - but (as any fool knows) these are held internally as Int32 so it doesnae work.
Replaced:
Code:
<MarshalAs(UnmanagedType.U2)> Public dmOrientation As PrintJob.DeviceOrientations
With:
Code:
Private mdmOrientation As Int16
'...
Public ReadOnly Property dmOrientation() As PrintJob.DeviceOrientations
Get
Return CType(mdmOrientation, PrintJob.DeviceOrientations)
End get
End property
Thanks all,
Duncan
-
March 24th, 2003, 11:30 AM
#3
You striked again...
...the OnlyOneGuru...which can resolve his own questions...
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|