0

I want to get the pixels of every physical screen individually, but MSDN says GetDC needs a window to know which screen to get the handle of. Is there any way of telling it which handle to use without using a window or mouse?

So I can call EnumDisplayDevices and as suggested loop through to find how many monitors are attached and the information of each: Problem is I am using the code provided by Microsoft:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd144942(v=vs.85).aspx

Using this code it has errors on the EnumDisplayDevices call "Too many arguments in function call"

BOOL GetDisplayMonitorInfo(int nDeviceIndex, LPSTR lpszMonitorInfo)
{
    FARPROC EnumDisplayDevices;
    HINSTANCE  hInstUser32;
    DISPLAY_DEVICE DispDev;
    char szSaveDeviceName[33];
    BOOL bRet = TRUE;
    HRESULT hr;

    hInstUser32 = LoadLibrary("c:\\windows\User32.DLL");
    if (!hInstUser32) return FALSE;

    EnumDisplayDevices = (FARPROC)GetProcAddress(hInstUser32, "EnumDisplayDevicesA");
    if (!EnumDisplayDevices) {
        FreeLibrary(hInstUser32);
        return FALSE;
    }

    ZeroMemory(&DispDev, sizeof(DispDev));
    DispDev.cb = sizeof(DispDev);
    if (EnumDisplayDevices(NULL, nDeviceIndex, &DispDev, 0))
    {
        hr = StringCchCopy(szSaveDeviceName, 33, DispDev.DeviceName);
        if (FAILED(hr))
        {
        }
        EnumDisplayDevices(szSaveDeviceName, 0, &DispDev, 0);
        hr = StringCchCopy(lpszMonitorInfo, 129, DispDev.DeviceString);
        if (FAILED(hr))
        {
            // TODO: write error handler 
        }

    }
    else    {
        bRet = FALSE;
    }

    FreeLibrary(hInstUser32);

    return bRet;
}
jub0bs
  • 60,866
  • 25
  • 183
  • 186
Built on Sin
  • 351
  • 2
  • 6
  • 19
  • 1
    That's not where `user32.dll` lives. And you certainly don't need to use runtime linking. – David Heffernan Oct 14 '14 at 12:18
  • 1
    if i may ask : why are you manually loading windows-libraries in the first place? Thats completely unnecessary since you can dynamically link them, all of the LOAD/EXEC can be handled by windows ... – specializt Oct 14 '14 at 12:23
  • because I am very new and don't really know what I am doing. Just self teaching what I can find. If you could lead me to information on the subject I would be very grateful. – Built on Sin Oct 14 '14 at 12:26

1 Answers1

1

This was handled in KB117428 because of C to C++ code porting (i.e. that code was originally written in C).

The proposed solution is to properly handle the typedefs

typedef BOOL (WINAPI *EDDType)(LPCSTR,DWORD,PDISPLAY_DEVICEA,DWORD);

BOOL GetDisplayMonitorInfo(int nDeviceIndex, LPSTR lpszMonitorInfo)
{
    EDDType EnumDisplayDevices;
    HINSTANCE  hInstUser32;
    DISPLAY_DEVICE DispDev;
    char szSaveDeviceName[33];
    BOOL bRet = TRUE;
    HRESULT hr;

    hInstUser32 = LoadLibrary("c:\\windows\\User32.DLL"); // You forgot the double backslash
    if (!hInstUser32) return FALSE;

    EnumDisplayDevices = (EDDType)GetProcAddress(hInstUser32, "EnumDisplayDevicesA");
Marco A.
  • 43,032
  • 26
  • 132
  • 246