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(La youtKind.Sequen tial, CharSet = CharSet.Auto)]
internal class MonitorInfoEx {
public uint cbSize;
public RECT rcMonitor;
public RECT rcWork;
public UInt32 dwFlags;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=CCHDE VICENAME)]
public string szDeviceName;
}
[DllImport("user 32")]
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.WriteLi ne("Call to GetMonitorInfo failed");
}