Preventing crash messages in Windows
My application needs 开发者_Python百科to scan 3rd party files that often leads to crash. In order to overcome that, it uses a separate process to scan those files and whenever this process crashes my application just instantiates another one.
My problem is that after each crash I get Windows crash message: "AuxScanner has stopped working..."
How can I prevent this message and crash quietly?
I'm using named pipes for inter-process communication.
Thanks
See http://blogs.msdn.com/b/oldnewthing/archive/2004/07/27/198410.aspx: you can disable the program crash dialog (though you'll need to do so from inside the sub-process).
The way I read it, you want something like this in your sub-process:
#include <windows.h>
//...
SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
//or if you only care about Vista or newer:
//SetErrorMode(GetErrorMode() | SEM_NOGPFAULTERRORBOX);
Interesting question by the way - this might be interesting to stick into all kinds of software during development; it's quite annoying when your actively-developed code crashes (not unexpected), and then then everything waits, your UI changes focus, and it offers to (pointlessly) send a crash dump to microsoft...
If you're getting the "...hast stopped working" message that means you didn't handle the exception. Make sure the sections of code that can or might be inducing the crash are wrapped in try/catch blocks and handle the exceptions gracefully.
Handle your .NET (CLR) exceptions.
Handle your C++ exceptions.
Handle your SEH exceptions.
See http://blogs.msdn.com/b/kirush/archive/2008/04/24/global-crash-handler-for-c-application.aspx
Last resort: SetErrorMode(SEM_NOGPFAULTERRORBOX)
精彩评论