日志钩子问题
想使用日志钩子,先简单的写了个代码想先做个测试,可无法成功。
#include "stdafx.h"
#include <afxwin.h>
#include <fstream.h>
static HHOOK g_hLogHook=NULL;
//钩子变量
LRESULT CALLBACK WINAPI JournalLogProc(int iCode,WPARAM wParam, LPARAM lParam);
static HINSTANCE hdll_lib;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hdll_lib=hInstance;
if (g_hLogHook==NULL)
g_hLogHook = SetWindowsHookEx(WH_JOURNALRECORD,(HOOKPROC)JournalLogProc,hdll_lib,0); //安装日志钩子
while(true) Sleep(1000);
return 0;
}
LRESULT CALLBACK WINAPI JournalLogProc(int iCode,WPARAM wParam, LPARAM lParam)
{
if (iCode<0)
return CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
MessageBox(NULL,"aaaa","zzzz",MB_OK);
}
本想是,运行后收到键盘消息后会弹出一个对话框,可运行后屏幕机器不再响应任何消息,象屏幕被锁住了一样。
只有按ctrl-alt-del 才有反应。不知问题出在哪里,请各位指点。