键盘挂钩在Windows资源管理器中获取错误 [英] KeyBoard Hook get error on Window Explorer
问题描述
大家好,
我从窗口上的键盘挂钩开始.
现在,我在运行应用程序时遇到问题.
当我专注于任何程序时,例如:Skype,yahoo,firefox,chrome ...
我的钩子工作正常,
但是当我最小化所有这些内容并专注于桌面或窗口浏览器时,请按任意键
我的钩子出现错误,使我的窗口浏览器强制关闭,或者中断直到我停止钩子.
这是我的hook.dll代码:
Hi all,
I''m starting with Keyboard hook on window.
Now, I''m getting problem when running my application.
When I focus on any program such as: skype, yahoo, firefox, chrome...
my hook is working ok,
But when I minimized all them and focus on desktop or window explorer, press any key
my hook get error, that make my window explorer force close, or interrupt until I stop my hook.
This is my hook.dll code:
extern "C"{
__declspec(dllexport) LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION){
f1=fopen("d:\\Report.txt","a");
fputc((char)wParam, f1);
fclose(f1);
}
return CallNextHookEx(hGlobalHook, nCode, wParam, lParam);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
hinstDLL = LoadLibrary(TEXT("C:\\Hook.dll"));
hookProc = (HOOKPROC)GetProcAddress(hinstDLL, (LPCSTR)"KeyboardProc");
MYPROC proc;
if(hinstDLL == NULL)
printf("\nload dll fail");
else
printf("\nload dll finish");
if(hookProc == NULL)
printf("\nload func fail \n");
else
printf("\nload func finished\n");
hhookSysMsg = SetWindowsHookEx(
WH_KEYBOARD,
hookProc,
hinstDLL,
0);
proc = (MYPROC)GetProcAddress(hinstDLL, (LPCSTR)"SetGlobalHookHandle");
if(proc != NULL){
(proc)(hhookSysMsg);
}
getch();
return 0;
}
这是我的实现代码:
任何人都可以帮助我解决这个问题吗,
谢谢大家.
This is my implementation code:
Can any body help me to solve this,
Thanks all.
推荐答案
在64位Windows上运行时,使用32位hook DLL可能会发生这种情况.尽管以32位应用程序为焦点,但在以64位进程为焦点之前,所有程序都运行良好.
使用64位Windows时,请通过在32位计算机上测试程序来验证这一点,并且/或者检查当任何64位应用程序都具有焦点时是否还会出现问题.
This may occur with a 32-bit hook DLL when running on a 64-bit Windows. While a 32-bit application has the focus, all is working well until a 64-bit process gets the focus.
When using a 64-bit Windows, verify this by testing your program on a 32-bit machine and/or check if the problem occurs also when any 64-bit application has the focus.
这篇关于键盘挂钩在Windows资源管理器中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!