全局钩子DLL写法,请问这里哪出错了
#include"stdafx.h"//这里面含windows.hHHOOKmyhook;LRESULTCALLBACKKeyboardProc(intcode,WPAR...
#include "stdafx.h" //这里面含windows.h
HHOOK myhook;
LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam)
{
return 1;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL,"dll加载成功","提示",0);
myhook = SetWindowsHookExA(2,KeyboardProc,GetModuleHandleA("abc"),0);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
UnhookWindowsHookEx(myhook);
MessageBoxA(NULL,"dll卸载成功","提示",0);
break;
}
return TRUE;
}
-------------------------------------------------------------------------------------
我用的是VS2008编写,生成DLL后我直接把这个abc.dll 用DLL注入品注入进一个记事本进程,在DLL入口函数加载时我挂起了全局键盘钩子。 注入后都弹出窗口“DLL加载成功” 但是我的键盘依次可以打字。是我按装钩子方法不对还是我代码那写错了,总之挂起钩子没起到作用。请各位高手帮我看一下。我编写时用的是VS2008. 展开
HHOOK myhook;
LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam)
{
return 1;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL,"dll加载成功","提示",0);
myhook = SetWindowsHookExA(2,KeyboardProc,GetModuleHandleA("abc"),0);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
UnhookWindowsHookEx(myhook);
MessageBoxA(NULL,"dll卸载成功","提示",0);
break;
}
return TRUE;
}
-------------------------------------------------------------------------------------
我用的是VS2008编写,生成DLL后我直接把这个abc.dll 用DLL注入品注入进一个记事本进程,在DLL入口函数加载时我挂起了全局键盘钩子。 注入后都弹出窗口“DLL加载成功” 但是我的键盘依次可以打字。是我按装钩子方法不对还是我代码那写错了,总之挂起钩子没起到作用。请各位高手帮我看一下。我编写时用的是VS2008. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询