帮帮忙,全局鼠标钩子的问题
我一个全局鼠标钩子,写成的lib,执行setwindowhookex成功,但是一直执行不到回调MyMouseProc里去,谁能帮我看看
代码如下:
// gMouse.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "gMouse.h"
#include <time.h>
#include <Windows.h>
///////////////////////////////////////////////////////////////
#pragma data_seg("shared")
static HMODULE g_hModule = NULL;
static HHOOK g_hhk = NULL;
#pragma data_seg()
#pragma comment(linker, "/SECTION:shared,rws")
///////////////////////////////////////////////////////////////
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hModule = hModule;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
LRESULT CALLBACK MyMouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
mm_time = time(NULL);
return CallNextHookEx(g_hhk, nCode,wParam,lParam);
}
///////////////////////////////////////////////////////////////
MOUSEHOOK_API BOOL InstallMouseHook()
{
if (NULL == g_hhk)
{
g_hhk = SetWindowsHookEx(WH_MOUSE_LL,MyMouseProc,g_hModule,NULL);
if (NULL != g_hhk)
{
return TRUE;
}
else
{
g_hhk = NULL;
}
}
return FALSE;
}
MOUSEHOOK_API BOOL UninstallMouseHook()
{
if (NULL != g_hhk)
{
return UnhookWindowsHookEx(g_hhk);
}
return TRUE;
}
[解决办法]
全局钩子写到DLL中,由别的程序调用