0

Im using low level mouse hooks in my program, and everything is fine with it until program crashes.

Lets say I do:

strcpy(0,"test");

That will ofcourse crash my program, but problem is that also it will make mouse almost to no unmoveable. I tend to fix most of problems in program, but debuging with unusable mouse is very hard. Is there any fix for this behaviour or is it possible to unhook it the moment crash occur?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
user3213103
  • 133
  • 3
  • 14
  • What platform are you talking about here? – Oliver Charlesworth May 10 '14 at 10:36
  • Strictly, there is nothing you can do - if you are using windows you might install a SEH-handler catching the exception and reset your hoook (if you are getting an exception) –  May 10 '14 at 10:44
  • 1
    Run the debugger on computer A. Run the program on computer B, possibly a VM running on computer A. Use remote debugging facilities. – n. m. could be an AI May 10 '14 at 10:46
  • answer is here. this is a duplicate question: http://stackoverflow.com/questions/457577/catching-access-violation-exceptions – Richard Hodges May 10 '14 at 10:51
  • 6
    Windows has a specific counter-measure against a misbehaving hook callback. If it doesn't return within 5 seconds then the hook get unceremoniously unregistered. My crystal ball says that you increased that timeout to debug your code and forgot to set it back. Or you are just complaining about that 5 second delay, that's normal of course. Code that affects *every* program that runs on the desktop has a higher demand on reliability. Use the non-standard __try/__except keywords to catch hard crashes in the callback. – Hans Passant May 10 '14 at 10:52
  • please explain? As far as I see it, the OP is causing a (hardware) access violation exception. This is catchable in windows via structured exception handling which can be trivially mapped to c++ exception handling. In unix it's caught with a signal handler. – Richard Hodges May 10 '14 at 11:03
  • 2
    Richard's solution may work for this case, but it won't catch *every* possible reason that your application may crash. This is why global hooks are dangerous and should be avoided whenever possible. There are usually better solutions. If you're certain that there are not in your case, then Hans's answer is the one you'll want to pay attention to. – Cody Gray - on strike May 10 '14 at 11:06
  • 1
    @HansPassant I think you should make this an answer. – πάντα ῥεῖ May 10 '14 at 11:10
  • Is this actually even a problem? Clearly non-responsive callbacks are an issue (hence the timeout implemented by Windows), but I would expect Windows to be smart enough to un-register any registered callbacks when it terminates a process (or else notice the process was gone the next time it tried to use the callback and un-register it then). – nobody May 10 '14 at 14:48
  • I will try to do something with exceptions. Anyway, regarding that timeouts is it possible to decrease value to less that 5s? I think even 1ms would be enough in my case as I don't do much per call. – user3213103 May 10 '14 at 17:32

0 Answers0