A
AlexS
Hi, I posted this in m.p.d.f.interop but did not get any sensible response.
Maybe somebody will be able to point me to right direction here?
Hi,
I am having some issue with EnumDisplayDevices when called from C#.
When I use CharSet.Ansi (note - no unicode) for DISPLAY_DEVICE structure, I
get
0, DISPLAY1, raphics SuperSavage/IXC 1014, 1548305232,
VEN_5333&DEV_8C2E&SUBSYS_01FC1014&REV_05,
ISTRY\Machine\System\ControlSet001\Services\S3SSavage\Device0
1, DISPLAY3, eeting driver, 0, ,
ISTRY\Machine\System\ControlSet001\Services\mnmdd\Device0
When I try to use unicode (CharSet.Auto) I get garbage in device name, key,
string etc.
Platform SDK help says that display_device structure strings must be
declared as WCHAR, which means unicode. Or not?
And why some strings are losing starting symbols?
Here is declaration I use
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class DISPLAY {
public long cb=0;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
public string DeviceName=new String(' ',32);
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceString=new String(' ',128);
public int StateFlags=0;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceID=new String(' ',128);
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceKey=new String(' ',128);
}
[DllImport("user32.dll")]
extern static bool EnumDisplayDevices(IntPtr lpDevice,
int iDevNum,
[In,Out] DISPLAY lpDisplayDevice,
int dwFlags);
and here is how function is called:
DISPLAY d=new DISPLAY();
d.cb=Marshal.SizeOf(d);
int id=0;
int dwf=0;
while (EnumDisplayDevices(IntPtr.Zero, id, d, dwf)) {
Console.WriteLine(
String.Format("{0}, {1}, {2}, {3}, {4}, {5}",
id,
d.DeviceName,
d.DeviceString,
d.StateFlags,
d.DeviceID,
d.DeviceKey
)
);
id++;
d.cb=Marshal.SizeOf(d);
}
What is wrong here?
Anybody can help?
Thanks
Alex
Maybe somebody will be able to point me to right direction here?
Hi,
I am having some issue with EnumDisplayDevices when called from C#.
When I use CharSet.Ansi (note - no unicode) for DISPLAY_DEVICE structure, I
get
0, DISPLAY1, raphics SuperSavage/IXC 1014, 1548305232,
VEN_5333&DEV_8C2E&SUBSYS_01FC1014&REV_05,
ISTRY\Machine\System\ControlSet001\Services\S3SSavage\Device0
1, DISPLAY3, eeting driver, 0, ,
ISTRY\Machine\System\ControlSet001\Services\mnmdd\Device0
When I try to use unicode (CharSet.Auto) I get garbage in device name, key,
string etc.
Platform SDK help says that display_device structure strings must be
declared as WCHAR, which means unicode. Or not?
And why some strings are losing starting symbols?
Here is declaration I use
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public class DISPLAY {
public long cb=0;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
public string DeviceName=new String(' ',32);
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceString=new String(' ',128);
public int StateFlags=0;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceID=new String(' ',128);
[MarshalAs( UnmanagedType.ByValTStr, SizeConst=128)]
public string DeviceKey=new String(' ',128);
}
[DllImport("user32.dll")]
extern static bool EnumDisplayDevices(IntPtr lpDevice,
int iDevNum,
[In,Out] DISPLAY lpDisplayDevice,
int dwFlags);
and here is how function is called:
DISPLAY d=new DISPLAY();
d.cb=Marshal.SizeOf(d);
int id=0;
int dwf=0;
while (EnumDisplayDevices(IntPtr.Zero, id, d, dwf)) {
Console.WriteLine(
String.Format("{0}, {1}, {2}, {3}, {4}, {5}",
id,
d.DeviceName,
d.DeviceString,
d.StateFlags,
d.DeviceID,
d.DeviceKey
)
);
id++;
d.cb=Marshal.SizeOf(d);
}
What is wrong here?
Anybody can help?
Thanks
Alex