helos,
开发者_如何转开发on WinXP my application has been sucessfully using a global mousehook to retrieve mouseposition and clicks even if it does not have the focus. the hook is in a separate .dll and is being initialized like this (in delphi):
SetWindowsHookEx(WH_MOUSE, @MouseHookCB, HInstance , 0);
now on Win7 this basically also works during runtime but i can no longer debug my application nicely (which i can under XP). as soon as i hit a breakpoint, Win7 freezes completely. i cannot switch to another process (even taskmanager fails to open). if i am lucky i can stop my process in the IDE. most of the times though i have to restart/logoff to regain access.
i know the problem is related to the mouse-hook as it is not present if i don't use the hook. this is even if my hookprocedure does nothing but the following:
CallNextHookEx(MouseHook, Code, wParam, lParam);
ie. simply the presence of the hook causes the troubles.
having the globalhooks.dll write something into the EventLog i see that it is still active even while i am on a breakpoint.
i tried to use a lowlevelmouse hook via WH_MOUSE_LL which basically works but gives me strange mouse-move delays while installing the hook and sometimes while resizing a window. also there is a freeze for some seconds when hitting a breakpoint but at least the system recovers after ~5 seconds... therefore this option is even worse as it also affects runtime.
any idea why the WH_MOUSE hook freezes my app during debugging in the first place?
if you're debugging an APP you shouldn't use HInstance. You're injecting the .exe itself into the global process, when debugging you are halting all mouse processing which could explain your issue.
SetWindowsHookEx documentation states to pass 0 when hoocking into own process and handle to a DLL when hoocking into a remote or global process.
Also make sure MouseHookCB() is resturning the value of CallNextHookEx.
精彩评论