Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than Structures, prefix the name with the module name and a period.
DevMode (Structures)
.
C# Definition:
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
struct DEVMODE
{
public const int CCHDEVICENAME = 32;
public const int CCHFORMNAME = 32;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
[System.Runtime.InteropServices.FieldOffset(0)]
public string dmDeviceName;
[System.Runtime.InteropServices.FieldOffset(32)]
public Int16 dmSpecVersion;
[System.Runtime.InteropServices.FieldOffset(34)]
public Int16 dmDriverVersion;
[System.Runtime.InteropServices.FieldOffset(36)]
public Int16 dmSize;
[System.Runtime.InteropServices.FieldOffset(38)]
public Int16 dmDriverExtra;
[System.Runtime.InteropServices.FieldOffset(40)]
public DM dmFields;
[System.Runtime.InteropServices.FieldOffset(44)]
public POINTL dmPosition;
[System.Runtime.InteropServices.FieldOffset(52)]
public Int32 dmDisplayOrientation;
[System.Runtime.InteropServices.FieldOffset(56)]
public Int32 dmDisplayFixedOutput;
[System.Runtime.InteropServices.FieldOffset(60)]
public short dmColor; // See note below!
[System.Runtime.InteropServices.FieldOffset(62)]
public short dmDuplex; // See note below!
[System.Runtime.InteropServices.FieldOffset(64)]
public short dmYResolution;
[System.Runtime.InteropServices.FieldOffset(66)]
public short dmTTOption;
[System.Runtime.InteropServices.FieldOffset(68)]
public short dmCollate; // See note below!
[System.Runtime.InteropServices.FieldOffset(72)]
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
public string dmFormName;
[System.Runtime.InteropServices.FieldOffset(102)]
public Int16 dmLogPixels;
[System.Runtime.InteropServices.FieldOffset(104)]
public Int32 dmBitsPerPel;
[System.Runtime.InteropServices.FieldOffset(108)]
public Int32 dmPelsWidth;
[System.Runtime.InteropServices.FieldOffset(112)]
public Int32 dmPelsHeight;
[System.Runtime.InteropServices.FieldOffset(116)]
public Int32 dmDisplayFlags;
[System.Runtime.InteropServices.FieldOffset(116)]
public Int32 dmNup;
[System.Runtime.InteropServices.FieldOffset(120)]
public Int32 dmDisplayFrequency;
}
VB.NET Definition:
<StructLayout(LayoutKind.Sequential)> _
Public Structure DEVMODE
Public Const CCHDEVICENAME As Integer = 32
Public Const CCHFORMNAME As Integer = 32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHDEVICENAME)> _
Public dmDeviceName As String
Public dmSpecVersion As Short
Public dmDriverVersion As Short
Public dmSize As Short
Public dmDriverExtra As Short
Public dmFields As DM
Public dmOrientation As Short
Public dmPaperSize As Short
Public dmPaperLength As Short
Public dmPaperWidth As Short
Public dmScale As Short
Public dmCopies As Short
Public dmDefaultSource As Short
Public dmPrintQuality As Short
Public dmColor As Short
Public dmDuplex As Short
Public dmYResolution As Short
Public dmTTOption As Short
Public dmCollate As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHFORMNAME)> _
Public dmFormName As String
Public dmLogPixels As Short
Public dmBitsPerPel As Integer ' Declared wrong in the full framework
Public dmPelsWidth As Integer
Public dmPelsHeight As Integer
Public dmDisplayFlags As Integer
Public dmDisplayFrequency As Integer
Public dmICMMethod As Integer
Public dmICMIntent As Integer
Public dmMediaType As Integer
Public dmDitherType As Integer
Public dmReserved1 As Integer
Public dmReserved2 As Integer
Public dmPanningWidth As Integer
Public dmPanningHeight As Integer
Public dmPositionX As Integer ' Using a PointL Struct does not work
Public dmPositionY As Integer
End Structure
The C# new structure allow to work with secondary monitor. In intitial structure fields order and alignment was wrong.
Tips & Tricks:
Since the DEVMODE members beyond dmDisplayFrequency do not have to be declared, the structure can vary in size. You should set dmSize to effective size of your implemetation before calling API functions:
DEVMODE d = new DEVMODE();
d.dmSize = Marshal.SizeOf(typeof(DEVMODE));
This way the API is informed of the version of DEVMODE used.
If you use Reflector, you can find Microsoft's managed version of the structure.
As of .net 3.5 the DEVMODE structure is declared incorrectly causing incorrect values to be returned after dmBitsPerPel. The structures above have been updated to reflect the correct implementation.
POINTL was incorrectly declared to use longs instead of ints, this has been fixed.
Instead of the definitions
public short dmColor;
public short dmDuplex;
public short dmCollate;
your can also use
public DMCOLOR dmColor;
public DMDUP dmDuplex;
public DMCOLLATE dmCollate;
This code (taken from .NET source code) is working with System.Drawing.Printing.PrinterSettings.Gethdevmode, where default structure doesn't work for me.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME2)]
public string dmDeviceName;
public Int16 dmSpecVersion;
public Int16 dmDriverVersion;
public Int16 dmSize;
public Int16 dmDriverExtra;
public DM dmFields;
public Int16 dmOrientation;
public Int16 dmPaperSize;
public Int16 dmPaperLength;
public Int16 dmPaperWidth;
public Int16 dmScale;
public Int16 dmCopies;
public Int16 dmDefaultSource;
public Int16 dmPrintQuality;
public POINTL dmPosition;
public Int32 dmDisplayOrientation;
public Int32 dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME2)]
public string dmFormName;
public Int16 dmLogPixels;
public Int32 dmBitsPerPel;
public Int32 dmPelsWidth;
public Int32 dmPelsHeight;
public Int32 dmDisplayFlags;
//public Int32 dmNup;
public Int32 dmDisplayFrequency;
}
Sample Code:
Please add some!
>
...
[DllImport("kernel32.dll", ExactSpelling = true)]
public static extern IntPtr GlobalSize(IntPtr handle);