I'm trying to count the number of monitors (i.e. screens) attached to the console from a service application. I do the following:
int nCnt = 0;
if(!EnumDisplayMonitors(NULL, NULL, _countMonitorEnumProc, (LPARAM)&nCnt))
nCnt = -1;
BOOL _countMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
int* pCnt = (int*)dwData;
but the count is always 1 (when I'm testing it on a dual-monitor Windows 7.) I then do this (which is not exactly what I need due to its limitation):
int nCnt = GetSystemMetrics(SM_CMONITORS);
and the result is also 1.
So how do you count monitors from a service?
First, why is the console special to a service, vs number of displays attached on a remote session? Then, what about display mirroring / extended desktop / eyefinity?
Now, learn about Window Stations and Desktops. Then learn about shatter attacks.
Finally, if what you're really after is hardware enumeration, there are APIs for that.
SetupDiGetClassDevs on the display monitor setup class will tell you how many physical screens the video card(s) expose.