我做了一个扩展Dll,挂一个WH_KEYBOARD钩子,但只能对调用该DLL的进程的键盘才起作用,为什么不能对全系统进程起作用?程序如下:
#pragma data_seg("Shared")
HHook g_hhook=NULL;
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
HINSTANCE g_hinstdll=NULL;DllMain(HINSTANCE hinstance,...){
...
if(dwReason=DLL_PROCESS_ATTACH)
g_hinstdll=hinstance;
...
}__declspec(dllexport) bool winapi SetKeyBoardHood(DWORD dw)
{
...
g_hhook=SetWindowHookEx(WH_KEYBOARD,GetMsgProc,g_hinstance,0);
// 这里是0,应该是系统钩子了阿
...}LRESULT winapi GetMsgProc(int ncode,WPARAM wParam,LPARAM lParam)
{
LRESULT result=CallNextHookEx(g_hhook,ncode,wParam,lParam);
TRACE("%c",LOWORD(wParam));
return result;
}
在这里只能输出调用该dll进程的键盘值,为什么挂不上全系统的?请各位帮帮忙.
#pragma data_seg("Shared")
HHook g_hhook=NULL;
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
HINSTANCE g_hinstdll=NULL;DllMain(HINSTANCE hinstance,...){
...
if(dwReason=DLL_PROCESS_ATTACH)
g_hinstdll=hinstance;
...
}__declspec(dllexport) bool winapi SetKeyBoardHood(DWORD dw)
{
...
g_hhook=SetWindowHookEx(WH_KEYBOARD,GetMsgProc,g_hinstance,0);
// 这里是0,应该是系统钩子了阿
...}LRESULT winapi GetMsgProc(int ncode,WPARAM wParam,LPARAM lParam)
{
LRESULT result=CallNextHookEx(g_hhook,ncode,wParam,lParam);
TRACE("%c",LOWORD(wParam));
return result;
}
在这里只能输出调用该dll进程的键盘值,为什么挂不上全系统的?请各位帮帮忙.
也设成共享数据段试试~