Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Correct Usage of LPDWORD

Tags:

c++

winapi

I have an array of hWnds of buttons that I want to monitor for clicks. I also have an array of HWINEVENTHOOKs that I will use to monitor them. GetWindowThreadProcessID gives me an LPDWORD process ID, which is not accepted by SetWinEventHook. I am unclear on whether I am correctly using LPDWORDs in this example. Please could somebody point me in the right direction?

EDIT: Thank you to everyone who contributed, I have posted the corrected code below.

New Code:

int i = 0;
for (HWND hWnd : hWnds) {
    DWORD processID = 0;
    DWORD threadID = GetWindowThreadProcessId(hWnd, &processID);
    hooks[i] = SetWinEventHook(EVENT_OBJECT_INVOKED, EVENT_OBJECT_INVOKED, 
    NULL,
        WinEventProcCallback, processID, threadID, WINEVENT_OUTOFCONTEXT);
        i++;
}
like image 309
JPadley Avatar asked Dec 02 '25 07:12

JPadley


1 Answers

LPDWORD is just a typedef for DWORD* and when a Windows SDK function parameter is a "LPsomething" you generally need to pass a pointer to a "something" (except for the LP[C][W]STR string types).

DWORD processID;
DWORD threadID = GetWindowThreadProcessId(hWnd, &processID);
if (threadID)
{
  // Do something with threadID and/or processID
}

The Windows SDK uses Systems Hungarian notation for the Desktop/Classic API.

like image 149
Anders Avatar answered Dec 04 '25 22:12

Anders