Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Modal Dialog on win32 process crash

Tags:

c++

winapi

We have a legacy build infrastructure for nightly builds (implemented in Perl) to compile, link and unit tests our applications/plugins. On Windows, if the unit testing process crashes, this pops up a Modal Dialog which "locks" our build farm.

Is there a way (win32 API call, system config, env var, something...) to disable this behavior to have the child process terminate immediately on crashes, with no Modal Dialog and a non-zero exit status instead?

Thanks, --DD

PS: We compile with SEC (Structured Exception Handling) on Windows, to be able to "catch" crashes using catch (...), therefore avoiding this issue most of the time, but sometime that's not enough, since of course some crashes are not recoverable (if they corrupted the stack for example).

like image 318
ddevienne Avatar asked Dec 07 '09 17:12

ddevienne


2 Answers

Depending on who's throwing the dialog, you may have to combine multiple approaches.

    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);

...will shut up one set of dialogs.

like image 98
Dewayne Christensen Avatar answered Nov 03 '22 00:11

Dewayne Christensen


You need to add an 'unhandled exception handler' that catches all exceptions: put a call to SetUnhandledExceptionFilter(handler) in your initialisation code and it'll call the handler routine. Really simple.

I use sample code from an old article, include a file called minidumper, call the exposed function, and you're done.

Here's some more example code, this pops a different dialog, but you can change that to simply write a message to a log file or similar.

If you're writing a pure .NET app, then you'll be more interested in this article.

like image 33
gbjbaanb Avatar answered Nov 03 '22 00:11

gbjbaanb