Results 1 to 2 of 2

Thread: Marshallin error trying to get DEVMODE from JOB_INFO_2

  1. #1

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Marshallin error trying to get 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:
    VB Code:
    1. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
    2. Friend Class DEVMODE
    3.     <VBFixedString(32), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public pDeviceName As String  'CCHDEVICENAME
    4.     Public dmSpecversion As Int16
    5.     Public dmSize As Int16
    6.     Public dmDriverExtra As Int16
    7.     Public dmFields As Int32
    8.     <MarshalAs(UnmanagedType.U2)> Public dmOrientation As PrintJob.DeviceOrientations
    9.     <MarshalAs(UnmanagedType.U2)> Public dmPaperSize As PrintJob.PrinterPaperSizes
    10.     Public dmPaperLength As Int16
    11.     Public dmPaperWidth As Int16
    12.     Public dmScale As Int16
    13.     Public dmCopies As Int16
    14.     Public dmDefaultSource As Int16
    15.     Public dmPrintQuality As Int16
    16.     <MarshalAs(UnmanagedType.U2)> Public dmColor As PrintJob.DeviceColourModes
    17.     <MarshalAs(UnmanagedType.U2)> Public dmDuplex As PrintJob.DeviceDuplexSettings
    18.     Public dmYResolution As Int16
    19.     Public dmTTOption As Int16
    20.     Public dmCollate As Int16
    21.     <VBFixedString(32), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Public dmFormName As String
    22.     Public dmUnusedPadding As Int16
    23.     Public dmBitsPerPel As Int16
    24.     Public dmPelsWidth As Int32
    25.     Public dmPelsHeight As Int32
    26.     Public dmDisplayFlags As Int32
    27.     Public dmDisplayFrequency As Int32
    28.  
    29. End Class

    and the JOB_INFO_2 defined thus:-
    VB Code:
    1. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
    2. Friend Class JOB_INFO_2
    3.     Public JobId As Int32
    4.     <MarshalAs(UnmanagedType.LPStr)> Public pPrinterName As String
    5.     <MarshalAs(UnmanagedType.LPStr)> Public pMachineName As String
    6.     <MarshalAs(UnmanagedType.LPStr)> Public pUserName As String
    7.     <MarshalAs(UnmanagedType.LPStr)> Public pDocument As String
    8.     <MarshalAs(UnmanagedType.LPStr)> Public pNotifyName As String
    9.     <MarshalAs(UnmanagedType.LPStr)> Public pDatatype As String
    10.     <MarshalAs(UnmanagedType.LPStr)> Public pPrintProcessor As String
    11.     <MarshalAs(UnmanagedType.LPStr)> Public pParameters As String
    12.     <MarshalAs(UnmanagedType.LPStr)> Public pDriverName As String
    13.     <MarshalAs(UnmanagedType.LPStruct)> Public DeviceMode As DEVMODE
    14.     <MarshalAs(UnmanagedType.LPStr)> Public pStatus As String
    15.     <MarshalAs(UnmanagedType.U4)> Public Status As PrintJob.Print_Job_Statuses
    16.     Public Priority As Int32
    17.     Public Position As Int32
    18.     Public TotalPage As Int32
    19.     Public PagesPrinted As Int32
    20.     <MarshalAs(UnmanagedType.Struct)> Public Submitted As SystemTime
    21. 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
    VB Code:
    1. Marshal.PtrToStructue(lpDevModePtr, dmThis)
    I get the same error.

    Thanks in advance,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  2. #2

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    [Resolved] Marshalling error getting DEVMODE from JOB_INFO_2

    Sigh - often the case that as soon as you post something all over the internet you spot the obvious error. Anyway - the line:
    VB Code:
    1. <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:-
    VB Code:
    1. Private mdmOrientation As Int16
    2. '...
    3. Public ReadOnly Property dmOreintation() As PrintJob.DeviceOrientations
    4.   Get
    5.     Return CType(mdmOrientation, PrintJob.DeviceOrientations)
    6.   End Get
    7. End Property
    8. '...
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width