Thanks for the reply, but...
Using a C# or C++ example of how to use EnumDisplaySettings would be
great, but the translation is exactly what I'm having the trouble with.
First problem: You can't do fixed-length fields in VB.Nt to declare the
DEVMODE Structure, so I put a couple of fields in there to act as filler
to take up the right amount of bytes.
Next problem: Then I get the next error, which is how do you pass VB's
Structure data type to a Win32 API function call without getting the
exception to the effect of "there is no object instance".
I'd like to figure out how to do this within VB.Net if anyone knows how
to do this.
Thanks,
Mark
' VB translation...
Public Const SA_SIZE As Integer = 32
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Structure DEVMODE
Public iSpecVersion As Short
Public iDriverVersion As Short
Public iSize As Short
Public iDriverExtra As Short
Public iFields As Integer
Public iOrientation As Short
Public iPaperSize As Short
Public iPaperLength As Short
Public iPaperWidth As Short
Public iScale As Short
Public iCopies As Short
Public iDefaultSource As Short
Public iPrintQuality As Short
Public iColor As Short
Public iDuplex As Short
Public iYRes As Short
Public iTTOption As Short
public iCollate As Short
// marsahalling attr...
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=SA_SIZE)> _
Public lpszFormName As String
Public iLogPixels As Short
Public iBitsPerPixel As Integer
Public lPelsWidth As Integer
Public lPelsHeight As Integer
Public lDisplayFlags As Integer
Public lDisplayFreq As Integer
Public lICMMethod As Integer
Public lICMIntent As Integer
Public lMediaType As Integer
Public lDitherType As Integer
Public lReserved1 As Integer
Public lReserved2 AS Integer
Public lPanWidth As Integer
Public lPanHeight As Integer
End Structure
Class LibWrapper
Public Declare Auto Function EnumDisplaySettings Lib "user32" _
(ByVal lpszDeviceName As String, _
ByVal lModeNum As Integer, _
ByRef lpdm As DEVMODE) As Boolean
Public Declare Auto Function ChangeDisplaySettings Lib "user32" _
(ByRef lpdm DEVMODE, ByVal iFlags As Integer) As Integer
End Class
Public Sub Main()
Dim dm As New DEVMODE()
Dim lMode As Integer = -1
dm.iSize = CType(Marshal.SizeOf(dm), Short)
Dim b As Boolean = LibWrapper.EnumDisplaySettings( _
Nothing, _
lMode, _
dm)
End Sub
Barring typo's should work...