求问SetWindowsHookEx出错的有关问题
求问SetWindowsHookEx出错的问题
rt,调试程序的时候程序只想到SetWindowsHookEx部分一直出错,GetLastError()返回3435973836,不知道到底错在哪里,求指点~
调试用的是visual studio 2010,管理员模式运行,hWndProc为NULL
extern "C" HOOKDLL_API int WINAPI SetHook(int thread_id)
{
/*SetWindowsHookEx: dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure
is to be associated. If this parameter is zero, the hook procedure is
associated with all existing threads running in the same desktop as the
calling thread.*/
threadId = thread_id;
// HHook hWndProc;
// 设置消息全局钩子
//if (hApiHook == NULL)
//hApiHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookDeal, hdll, threadId);
// 设置CALLWNDPROC全局钩子以拦截SendMessage消息
if (hWndProc == NULL)
{
hWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)MyWndProc, hdll, threadId);
DWORD errorno = GetLastError();
SendMsgToAllWnd(WM_APIHOOK_SET);
}
// test
Logs("SetWindowsHookEx hWndProc", (int)hWndProc);
return (hApiHook || hWndProc) ? 1 : 0;
}
------解决方案--------------------
把你的
HINSTANCE hdll = NULL;改成:
HINSTANCE hdll = GetModuleHandle("你的dll名字或路径");
之后在调用 SetWindowsHookEx
rt,调试程序的时候程序只想到SetWindowsHookEx部分一直出错,GetLastError()返回3435973836,不知道到底错在哪里,求指点~
调试用的是visual studio 2010,管理员模式运行,hWndProc为NULL
extern "C" HOOKDLL_API int WINAPI SetHook(int thread_id)
{
/*SetWindowsHookEx: dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure
is to be associated. If this parameter is zero, the hook procedure is
associated with all existing threads running in the same desktop as the
calling thread.*/
threadId = thread_id;
// HHook hWndProc;
// 设置消息全局钩子
//if (hApiHook == NULL)
//hApiHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookDeal, hdll, threadId);
// 设置CALLWNDPROC全局钩子以拦截SendMessage消息
if (hWndProc == NULL)
{
hWndProc = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)MyWndProc, hdll, threadId);
DWORD errorno = GetLastError();
SendMsgToAllWnd(WM_APIHOOK_SET);
}
// test
Logs("SetWindowsHookEx hWndProc", (int)hWndProc);
return (hApiHook || hWndProc) ? 1 : 0;
}
------解决方案--------------------
把你的
HINSTANCE hdll = NULL;改成:
HINSTANCE hdll = GetModuleHandle("你的dll名字或路径");
之后在调用 SetWindowsHookEx