none
钩子使用中的问题 RRS feed

  • 问题

  • 想实现一个功能,当鼠标按下的时候就输入一串文字。就监控鼠标WM_LBUTTONDOWN的消息。但是这个时候有个线程一直在组织数据,我的想法是在钩子中使用WaitForSingleObject来等待线程中传递过来的信息激活。但是钩子在使用中执行到WaitForSingleObject的时候完全没有等待。网上找了许多资料也不明白为什么。如果检测到钩子后,就输入数据,但是另一个线程也在输入数据,这个时候在输入数据接口中加锁防止数据不对。突然想起来,钩子中WaitForSingleObject都不能等待,那加锁还能起到效果吗。
    2012年7月9日 16:49

答案

  • 钩子不能等的,系统如果检测到你的钩子挂起了会取消你的钩子的


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年7月9日 17:46
    版主

全部回复

  • 钩子不能等的,系统如果检测到你的钩子挂起了会取消你的钩子的


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    2012年7月9日 17:46
    版主
  • MSDN上对SetWindowsHookEx的钩子过程函数中有这么一段:

    The hook procedure should process a message in less time than the data entry
    specified in the LowLevelHooksTimeout value in the following registry key:

    HKEY_CURRENT_USER\Control Panel\Desktop

    The value is in milliseconds. If the hook procedure does not return during
    this interval, the system will pass the message to the next hook.


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2012年7月9日 23:02
    版主