J
JackRazz
I'm having problems trying to call GetMonitorInfo. I believe the problem has
something to do with the szDeviceName. Passing a MonitorInfo struct works fine. I
added the szDeviceName and the struct is filled with garbage. What am I doing
wrong??
Thanks - JackRazz
Pretty version of this snippet is here: http://rafb.net/paste/results/M3114698.html
private const int CCHDEVICENAME = 32;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class MonitorInfoEx {
public uint cbSize;
public RECT rcMonitor;
public RECT rcWork;
public UInt32 dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)]
public string szDeviceName;
}
[DllImport("user32")]
internal static extern bool GetMonitorInfo( IntPtr hMonitor, [Out]
MonitorInfoEx lpmi );
MonitorInfoEx mi = new MonitorInfoEx();
mi.cbSize =(uint) Marshal.SizeOf(mi);
bool result = GetMonitorInfo( hMonitor, mi ) ;
if ( result ) {
Mon.MonitorArea= mi.rcMonitor;
Mon.WorkArea= mi.rcWork;
Mon.Flags = (int) mi.dwFlags;
Mon.hMonitor = hMonitor;
//Mon.deviceName=mi.szDeviceName;
}
else {
Console.WriteLine("Call to GetMonitorInfo failed");
}
something to do with the szDeviceName. Passing a MonitorInfo struct works fine. I
added the szDeviceName and the struct is filled with garbage. What am I doing
wrong??
Thanks - JackRazz
Pretty version of this snippet is here: http://rafb.net/paste/results/M3114698.html
private const int CCHDEVICENAME = 32;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class MonitorInfoEx {
public uint cbSize;
public RECT rcMonitor;
public RECT rcWork;
public UInt32 dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)]
public string szDeviceName;
}
[DllImport("user32")]
internal static extern bool GetMonitorInfo( IntPtr hMonitor, [Out]
MonitorInfoEx lpmi );
MonitorInfoEx mi = new MonitorInfoEx();
mi.cbSize =(uint) Marshal.SizeOf(mi);
bool result = GetMonitorInfo( hMonitor, mi ) ;
if ( result ) {
Mon.MonitorArea= mi.rcMonitor;
Mon.WorkArea= mi.rcWork;
Mon.Flags = (int) mi.dwFlags;
Mon.hMonitor = hMonitor;
//Mon.deviceName=mi.szDeviceName;
}
else {
Console.WriteLine("Call to GetMonitorInfo failed");
}