简体   繁体   English

C ++正确使用LPDWORD

[英]C++ Correct Usage of LPDWORD

I have an array of hWnds of buttons that I want to monitor for clicks. 我有一个要监视点击次数的hWnds数组。 I also have an array of HWINEVENTHOOKs that I will use to monitor them. 我还有一组HWINEVENTHOOK,将用来监视它们。 GetWindowThreadProcessID gives me an LPDWORD process ID, which is not accepted by SetWinEventHook. GetWindowThreadProcessID给我一个LPDWORD进程ID,SetWinEventHook不接受。 I am unclear on whether I am correctly using LPDWORDs in this example. 我不清楚在此示例中我是否正确使用了LPDWORD。 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++;
}

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). LPDWORD只是DWORD*的typedef,并且Windows SDK函数参数为“ LPsomething”时,通常需要将指针传递给“ something”(LP [C] [W] STR字符串类型除外)。

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. Windows SDK将“ 系统匈牙利语”表示法用于Desktop / Classic API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM