Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:07:01+00:00 2026-05-30T15:07:01+00:00

I’m trying to get info on my monitors programmatically. The content of the loops

  • 0

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++;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:07:02+00:00Added an answer on May 30, 2026 at 3:07 pm

    The problem is passing ‘dd’ into the inner call while using a member of ‘dd’ as the input string. I know this doesn’t make sense, but I suspect that since dd is an out parameter the API is writing to it, but then looking that the contents of the input parameter after it has scribbled on it. This could happen if they did something like memset’ing the output parm to 0 before execution for sanity.

    Just make sure it wasn’t something about sending in a non-empty dd, I made a second dd with the exact same bits in it and things still work fine. It’s definitely the aliased memory.

    #include <windows.h>
    #include <stdio.h>
    
    #pragma comment(lib, "user32.lib")
    
    void DumpDevice(const DISPLAY_DEVICE& dd, size_t nSpaceCount )
    {
        printf("%*sDevice Name: %s\n", nSpaceCount, "", dd.DeviceName );
        printf("%*sDevice String: %s\n", nSpaceCount, "", dd.DeviceString );
        printf("%*sState Flags: %x\n", nSpaceCount, "", dd.StateFlags );
        printf("%*sDeviceID: %s\n", nSpaceCount, "", dd.DeviceID );
        printf("%*sDeviceKey: ...%s\n\n", nSpaceCount, "", dd.DeviceKey+42 );
    }
    
    int main()
    {
        DISPLAY_DEVICE dd;
    
        dd.cb = sizeof(DISPLAY_DEVICE);
    
        DWORD deviceNum = 0;
        while( EnumDisplayDevices(NULL, deviceNum, &dd, 0) ){
            DumpDevice( dd, 0 );
            DISPLAY_DEVICE newdd = {0};
            newdd.cb = sizeof(DISPLAY_DEVICE);
            DWORD monitorNum = 0;
            while ( EnumDisplayDevices(dd.DeviceName, monitorNum, &newdd, 0))
            {
                DumpDevice( newdd, 4 );
                monitorNum++;
            }
            puts("");
            deviceNum++;
        }
    
        return 0;
    }
    

    The box I’m on right now only has 1 monitor, so I can’t verify the inner loop, but I suspect it’s fine since ‘newdd’ never gets aliased into the call. You also say you are in a service context – I’m not sure if that winstation will restrict what you see about the displays – so that could also be a problem; but I suspect you should still be able to at least see the physical device. On my machine I get:

    Device Name: \\.\DISPLAY1
    Device String: NVIDIA GeForce GTX 580
    State Flags: 8000005
    DeviceID: PCI\VEN_10DE&DEV_1080&SUBSYS_15803842&REV_A1
    DeviceKey: ...\Control\Video\{B0CDD262-FCFB-4FD4-A03C-54621896C9CD}\0000
    
       Device Name: \\.\DISPLAY1\Monitor0
       Device String: Generic PnP Monitor
       State Flags: 3
       DeviceID: MONITOR\DEL4016\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002
       DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0002
    
    Device Name: \\.\DISPLAY2
    Device String: NVIDIA GeForce GTX 580
    State Flags: 0
    DeviceID: PCI\VEN_10DE&DEV_1080&SUBSYS_15803842&REV_A1
    DeviceKey: ...\Control\Video\{B0CDD262-FCFB-4FD4-A03C-54621896C9CD}\0001
    
    Device Name: \\.\DISPLAYV1
    Device String: RDPDD Chained DD
    State Flags: 8
    DeviceID:
    DeviceKey: ...\Control\Video\{DEB039CC-B704-4F53-B43E-9DD4432FA2E9}\0000
    
    Device Name: \\.\DISPLAYV2
    Device String: RDP Encoder Mirror Driver
    State Flags: 200008
    DeviceID:
    DeviceKey: ...\Control\Video\{42cf9257-1d96-4c9d-87f3-0d8e74595f78}\0000
    
    Device Name: \\.\DISPLAYV3
    Device String: RDP Reflector Display Driver
    State Flags: 200008
    DeviceID:
    DeviceKey: ...\Control\Video\{b043b95c-5670-4f10-b934-8ed0c8eb59a8}\0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.