问题lowlevelkeyboardproc永远不会被调用

编程入门 行业动态 更新时间:2024-10-28 12:19:53
本文介绍了问题lowlevelkeyboardproc永远不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须将Windows CE应用程序移植到Windows XP. 在Windows CE中,此应用程序运行良好.它包含一个lowlevelkeyboardproc,当按下某个键时会调用它. 不同的Windows CE项目是使用几个makefile-,sources和& * .def-文件. 我使用Visual Studio 2010构建了新项目,并添加了* .cpp& * .h文件. 此外,代码中还包含一些Windows CE特定的内容,我将其替换为Windows XP的内容. 关于lowlevelkeyboardproc,我在现有Windows CE代码中未做任何更改. lowlevelkeyboardproc东西是在服务(* .exe)和DLL中实现的. 该服务将加载DLL. DLL是包含挂钩函数的部分. 1.在服务内部创建一个线程.关于lowlevelkeyboardproc,在此线程中完成了以下操作: -------------------------------------------------- -------------------------------------------------- -----------------------

Hi, I have to port a Windows CE application to Windows XP. In Windows CE this application runs fine. It contains a lowlevelkeyboardproc that is called when a key is pressed. The different Windows CE projects are build with several makefile-, sources- & *.def- files. I built new projects with Visual Studio 2010 and added the *.cpp & *.h files. Further there has been some Windows CE specific stuff in the code, which I replaced with Windows XP stuff. Concerning the lowlevelkeyboardproc I changed nothing in the existing Windows CE code. The lowlevelkeyboardproc stuff is implemented in a service (*.exe) and a DLL. The service loads the DLL. The DLL is the part that contains the hook function. 1. Inside the service a thread is created. Concerning the lowlevelkeyboardproc the following stuff is done in this thread: ---------------------------------------------------------------------------------------------------------------------------

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // MyServiceThread // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx DWORD WINAPI MyServiceThread (LPVOID lpParameter) { // ... some other code that is executed HMODULE hinstDLL = LoadLibrary(TEXT("MyHook.dll")); BOOL_FUNC pInstallHook = (BOOL_FUNC)GetProcAddress(hinstDLL,"InstallHook"); pInstallHook(); MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } BOOL_FUNC pUnInstallHook = (BOOL_FUNC)GetProcAddress(hinstDLL,"UnInstallHook"); pUnInstallHook(); // ... some other code that is executed return 0; } 2. the lowlevelkeyboardproc related stuff in my MyHook.dll is: --------------------------------------------------------------------------------------------------------------------------- ........ // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // DllMain // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx BOOL APIENTRY DllMain( HANDLE hModule, DWORD fdwReason, LPVOID lpReserved ) { static HANDLE hFileMap = NULL; if( DLL_PROCESS_ATTACH == fdwReason ) { InitializeCriticalSection(&csStatusPos); EnterCriticalSection(&csStatusPos); hFileMap = CreateFileMapping((HANDLE)-1, (LPSECURITY_ATTRIBUTES) NULL, PAGE_READWRITE, (DWORD) 0, (DWORD) sizeof(SHARED_MEM_VAR), TEXT("MY_SHARED_MEM_VAR") ); p_my_shared_mem = (PSHARED_MEM_VAR)MapViewOfFile( hFileMap, FILE_MAP_WRITE, (DWORD) 0, (DWORD) 0, (DWORD) sizeof(SHARED_MEM_VAR)); p_my_shared_mem->m_hDllInst = (HINSTANCE) hModule; p_my_shared_mem->m_MyKeyBoardHookObject = new MyKeyBoardHookClass; p_my_shared_mem->m_MyKeyBoardHookObject->Init(); .... LeaveCriticalSection(&csStatusPos); } if(DLL_PROCESS_DETACH == fdwReason) { EnterCriticalSection(&csStatusPos); delete p_my_shared_mem->m_MyKeyBoardHookObject; ..... UninstallHook(); UnmapViewOfFile( (LPCVOID) p_my_shared_mem); CloseHandle(hFileMap); LeaveCriticalSection(&csStatusPos); DeleteCriticalSection(&csStatusPos); } return TRUE; } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // InstallHook // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx EXTERN BOOL InstallHook() { p_my_shared_mem->m_hMyKeybdHook = SetWindowsHookEx( WH_KEYBOARD_LL, (HOOKPROC)MyLowLevelKeyboardHook, p_my_shared_mem->m_hDllInst, 0 ); return ! ( NULL == p_my_shared_mem->m_hMyKeybdHook ); } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // UninstallHook // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx EXTERN BOOL UninstallHook() { UnhookWindowsHookEx(p_my_shared_mem->m_hMyKeybdHook); return FALSE; } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // MyLowLevelKeyboardHook // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx EXTERN HOOKPROC MyLowLevelKeyboardHook(int nCode, WPARAM wParam, LPARAM lParam) { ........ } ........

1.有人可以看到为什么按下键时Windows XP中从不调用MyLowLevelKeyboardHook吗? 2.我尝试了很多东西来安装我的Hook....我在MSDN中阅读了很多有关Hooks& 的内容. 尤其是lowlevelkeyboardproc等...我在旧的论坛线程中搜索了解决方案. ... 但是我无法解决问题.我的钩子仍然没有被调用. ==>有人可以告诉我所有重要的要点吗? 获得自己的lowlevelkeyboardproc全局钩子. 3.是否有人知道与某个地方的良好链接,这些链接可以解释有关此主题的所有内容? 4.有人知道一个与地方的良好链接,并提供免费的示例代码吗? 预先感谢您的所有答复和帮助. 问候dave

1. Can somebody see, why MyLowLevelKeyboardHook is never called in Windows XP, when a key has been pressed? 2. I tried a lot of stuff to get my Hook installed.... I read a lot in the MSDN about Hooks & especially lowlevelkeyboardproc etc... I searched in old forum threads for a solution. ... But I wasn''t able to fix the problem. My hook still isn''t called. ==> Can somebody tell me please all the important points, that are required to get a own lowlevelkeyboardproc global hook working. 3. Does somebody know a good link(s) to a place(s), that explains everything about this topic? 4. Does somebody know a good link(s) to a place(s), with a good free sample code? Thanks in advance for all your answers and help. regards dave

推荐答案

您说这是在Windows Service中运行的?如果为true,则将无法正常运行,因为服务在其他桌面下运行.它没有收到键盘消息,因为没有必要将键盘和鼠标输入发送到用户看不到的桌面. 将您的服务标记为允许服务与桌面交互",这可能会解决问题. You said this was running in a Windows Service?? If true, it won''t work because services run under a different Desktop. It doesn''t get keyboard messages because theres no point in sending keyboard and mouse input to a desktop that the user cannot see. Tag your service as "Allow service to interact with desktop" and that MIGHT fix the problem.

感谢您的快速回答. 我设置了允许服务与桌面交互"复选框,现在调用了键盘挂钩. 但是不幸的是,在离开了键盘钩子功能之后,抛出了未处理的异常特权指令". 即使完全空了键盘挂钩功能,也会发生此错误: EXTERN HOOKPROC KeyboardHook(int nCode,WPARAM wParam,LPARAM lParam) { return(HOOKPROC)CallNextHookEx(hKeyboardHook,nCode,wParam,lParam); } 该问题如何解决? Thanks for that fast an good answer. I set the check box "Allow service to interact with desktop" and now the keyboard hook is called. But unfortunately the unhandled exception "privileged instruction" is thrown, after leaving the keyboard hook function. Even with a total empty keyboard hook function, this error occurs: EXTERN HOOKPROC KeyboardHook(int nCode, WPARAM wParam, LPARAM lParam) { return (HOOKPROC)CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); } How can this problem be solved?

更多推荐

问题lowlevelkeyboardproc永远不会被调用

本文发布于:2023-11-08 09:42:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569032.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:永远不会   lowlevelkeyboardproc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!