Enum HWND properties c++

666 views Asked by At

I am trying to get properties from an HWND. I'm used information from Using Window Properties, but the example below is not working for me. I'm getting an error while compiling my code.

argument of type "BOOL (__stdcall *)(HWND hwndSubclass, LPCSTR lpszString, HANDLE hData)" is incompatible with parameter of type "PROPENUMPROCEXW"

Here is my callback function

BOOL CALLBACK PropEnumProcEx(HWND hwndSubclass, LPCSTR lpszString, HANDLE hData) {
    return TRUE;
}

and this how I'm using it

EnumPropsEx(hwnd, PropEnumProcEx, NULL);

Does someone have any suggestions of how this can be fixed?

1

There are 1 answers

6
user7860670 On BEST ANSWER

LPCSTR lpszString should be LPTSTR lpszString. This argument should accept a pointer to either ANSI or Unicode null-terminated string. PROPENUMPROCEXW indicates that you are building Unicode application so EnumPropsEx macro expands to EnumPropsExW call so you need to provide callback accepting wide string as an argument. Typically you should always explicitly call Unicode variants of API functions.

Also you are missing last argument ULONG_PTR dwData.

So your callback should look like:

BOOL CALLBACK
PropEnumProcEx(HWND hwndSubclass, LPTSTR lpszString, HANDLE hData, ULONG_PTR dwData)
{
    return TRUE;
}