CLogic* g_Logic=NULL;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if(!g_Logic)
{
g_Logic = new CLogic();
}
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL,"1","~",MB_OK);
g_Logic->InstallHookKeyBoard();
break;
case DLL_THREAD_ATTACH:
MessageBoxA(NULL,"2","~",MB_OK);
break;
case DLL_THREAD_DETACH:
MessageBoxA(NULL,"3","~",MB_OK);
break;
case DLL_PROCESS_DETACH:
MessageBoxA(NULL,"4","~",MB_OK);
if(g_Logic)
{
delete g_Logic;
g_Logic = 0;
}
break;
}
return TRUE;
}
void CLogic::InstallHookKeyBoard()
{
if(0==hKeyBoardHook)
hKeyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL ,(HOOKPROC)LowLevelKeyboardProc ,GetModuleHandle("vcdll.dll"),0);
if(!hKeyBoardHook)
{
MessageBoxA(NULL,"键盘钩子安装失败","Err",MB_OK);
}
else
{
MessageBoxA(NULL,"键盘钩子安装成功","OK",MB_OK);
}
}
//键盘消息
LRESULT CALLBACK LowLevelKeyboardProc(
__in int nCode,
__in WPARAM wParam,
__in LPARAM lParam
)
{
MessageBox(NULL,"aaaaaaaa","",MB_OK);
return CallNextHookEx(g_Logic->hKeyBoardHook,nCode ,wParam ,lParam);
}
在dllmian未退出的时候,键盘输入可以捕获,如果dllmain一退出,就不行了,我是win7系统,谢谢了
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!