To manage display adapters and display properties, my code uses APIs from two different Windows DLLs:
CfgMgr32.dll
I use functions in CfgMgr32 (successor to SetupApi) to:
- enumerate adapters (get ids & properties)
- determine whether a specific adapter exists
- determine whether an adapter is enabled/disabled
- enabled/disabled an adapter
- register a callback to receive PnP device events
APIs in CfgMgr32 (and SetupApi) use an adapter id (called DeviceInstanceId or PNPDeviceID) of the form: "SWD\MyEnumerator\MyInstance"
User32.dll
I use functions in User32 to:
- enumerate adapters (get ids & properties)
- query an adapter's supported resolutions
- query an adapter's current display mode
- change an adapter's current orientation
- change an adapter's current resolution
APIs in User32 uses use a completely different adapter id (called DeviceName) of the form: "\\.\DISPLAY23"
The (Astonishing) Problem:
There appears to be no documented way of mapping between these two forms of unique identifiers. I can enable an adapter, but when I want to change its orientation or resolution, I have no way of knowing which of the identifiers returned by EnumDisplayDevices(...)
refers to the same adapter I just enabled.
The APIs I need are split across two libraries; neither library provides a complete set of display adapter management functions.
Both libraries have functions that let you get information about a particular adapter, and there is some minor overlap, but critically: nothing that's unique to a single adapter. Maybe there's some way to unambiguously relate properties from one side to the other, but I've dumped out everything that's available (including SystemInformation, Screen.AllScreens, Wmi queries like Win32_VideoController, DISPLAY_DEVICE...) and in all that information I can't find anything mappable.
Has anyone solved this, or know of some open source project that might be worth looking over?