Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum HWND properties c++

Tags:

c++

winapi

hwnd

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?

like image 376
Illia Moroz Avatar asked Aug 27 '17 09:08

Illia Moroz


1 Answers

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;
}
like image 171
user7860670 Avatar answered Sep 27 '22 22:09

user7860670