I am attempting to retrieve information on all the various monitors (and their adapters) present on a system. So far, my attempts at using EnumDisplayDevices
to list all the monitors has worked great - it found two, the first being "\\.\DISPLAY1\Monitor0"
(the second is just 2 and 1, respectively, but it's irrelevant to this question). Anyway, I then attempted to call EnumDisplaySettingsEx
on it, passing the name of the monitor as above, but it always fails. Calls with a null name parameter succeed, but the DEVMODE
structure returned says the dmDeviceName
is "cdd" which I highly doubt is accurate. What am I doing wrong?
Oh, and I've tried using EnumDisplaySettings
(the non-Ex one) and that doesn't even work with the null name parameter.
P/Invoke signatures (Ex's slightly modified from the one on pinvoke.net in a flailing attempt to get it to work):
[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
[DllImport("user32.dll", CharSet = CharSet.Ansi)]
public static extern bool EnumDisplaySettingsEx([MarshalAs(UnmanagedType.LPStr)]string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode, EdsDwFlags dwFlags);
DEVMODE
is defined at http://www.pinvoke.net/default.aspx/Structures/DEVMODE.html. EdsDwFlags
for now is always zero. iModeNum
is -1 (for current settings).
And for some reason StackOveflow won't let me attach a C# tag to this post.