Thread: EnumPropsEx Error

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    10

    EnumPropsEx Error

    Hello,

    I am trying to get the properties of a Microsoft's Notepad.exe window. I have an instance of this application running when I execute the code below.

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    BOOL CALLBACK PropEnumProcEx(HWND hwnd, LPTSTR lpszString, HANDLE hData, ULONG_PTR dwData) {
      cout << "Property Label: " << lpszString << "." << endl;
      return true;
    }
    
    int main()
    {
        HWND hNote = FindWindow("Notepad", NULL);
        cout << "Notepad's handle: " << hNote << endl;
        EnumPropsEx(hNote, PropEnumProcEx, 0);
        cout << "Done" << endl;
        return 0;
    }
    The output is:

    Notepad's handle: 0x7e0b7e
    Property Label:

    Then i receive a "properties.exe has encountered a problem and needs to close. We are sorry for the inconvenience." Windows error message.

    {P.S. my program is called properties.exe}

    If I don't have a reference to lpszString in the callback function then the code executes as expected through to the end. I suspect I am not using the pointer of the string correctly...?

    If someone could shed some light that would be appreciated.

    Thanks,

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Check return value of FindWindow().

    The incoming string may be a "global atom". See SetProp(). Check the high word before assuming it's a string.

    Call EnumPropsExA() since your code is expecting char strings (instead of wchar_t).

    gg
    Last edited by Codeplug; 05-30-2008 at 11:09 PM.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    10
    Yes, indeed it is an atom; namely, an integer atom.

    I changed the callback procedure to the following:
    Code:
    BOOL CALLBACK PropEnumProcEx(HWND hwnd, LPTSTR lpszString, HANDLE hData, ULONG_PTR dwData) {
      if (HIWORD(lpszString) == 0) {
        WORD the_atom = LOWORD(lpszString);
        char buffy[100] = {0};
        GetAtomName(the_atom, buffy, 100);
        cout << "It is an atom: " << buffy << endl;
        cout << "Data: " << hData << endl;
      }else {
        cout << "Property Label: " << lpszString << "." << endl;
      }
      return true;
    }
    I have two follow-ups.

    1. Winspector Spy shows there are two integer atoms, but I only get 1. What is going on here?
    2. What can I do with the hData handle?


    Thanks for your assistance,

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    1. A global atom not used in SetProp(), or in another window...?
    2. It's whatever was passed to SetProp(), so you can't do much unless you know what it is.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

Tags for this Thread