I'm trying to get info on my monitors programmatically. The content of the loops is not important right now, they just contain debug statements that will be printed when the loop condition is satisfied. Right now, the outer loop code executes three times and the inner loop code is never accessed, meaning the while condition of the (inner) loop is never true, meaning that call fails.
My problem here is that the Windows API says, regarding this function:
To obtain information on a display monitor, first call EnumDisplayDevices with lpDevice >set to NULL. Then call EnumDisplayDevices with lpDevice set to DISPLAY_DEVICE.DeviceName >from the first call to EnumDisplayDevices and with iDevNum set to zero. Then >DISPLAY_DEVICE.DeviceString is the monitor name.
...but even after doing exactly what it says, the second EnumDisplayDevices call always fails? Any insight???
Also I'm doing this as a service level application on both windows xp and windows 7 and getting the same results. When I try to print out dd.DeviceName, it gives me an address (for example: 0x12cfa4), but this must be what the function is expecting on the second call as MSDN says just pass in your display device pointer and append .DeviceName to it...
C++ (using Qt), Windows API/MSDN calls are used.
DISPLAY_DEVICE dd;
dd.cb = sizeof(DISPLAY_DEVICE);
DWORD deviceNum = 0;
while( EnumDisplayDevices(NULL, deviceNum, &dd, 0) ){
qWarning() << "We've entered the outer loop.";
while( EnumDisplayDevices(dd.DeviceName, 0, &dd, 0)){
qWarning() << "We've entered the inner loop.";
}
deviceNum++;
}