【发布时间】:2010-12-08 14:24:40
【问题描述】:
我正在尝试设置一个WH_CBT 钩子,它总是返回 0。
我检查了错误,得到了错误 1428。我进行了一些研究,发现 hMod 参数有问题,但我看不出应该放什么而不是 null。有谁知道我做错了什么?
这是我的代码:
#include "stdafx.h"
#include "Windows.h"
#include <iostream>
using namespace std;
HHOOK hookHandle;
LRESULT CALLBACK CBTProc( int nCode, WPARAM wParam, LPARAM lParam);
int _tmain(int argc, _TCHAR* argv[])
{
hookHandle = SetWindowsHookEx(WH_CBT,CBTProc,NULL,0);
if(hookHandle == NULL)
{
cout << "ERROR CREATING HOOK: ";
cout << GetLastError() << endl;
getchar();
return 0;
}
MSG message;
while(GetMessage(&message, NULL, 0, 0) != 0)
{
TranslateMessage( &message );
DispatchMessage( &message );
}
cout << "Press any key to quit...";
getchar();
UnhookWindowsHookEx(hookHandle);
return 0;
}
LRESULT CALLBACK CBTProc( int nCode,WPARAM wParam, LPARAM lParam)
{
cout << "hello" << endl;
return CallNextHookEx(hookHandle, nCode,
wParam, lParam);
}
附:如果代码中包含愚蠢的元素,我深表歉意。我不是编程新手,只是 C++。
【问题讨论】: