From 6198a00920004ced7334082d909e74610996e5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Sun, 3 Jun 2007 10:59:46 +0000 Subject: [PATCH] don't crash when closing the console window (win only), thanks to etil for the patch Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2866 --- src/gui/sdlmain.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index bb0b7ead..f25f3805 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sdlmain.cpp,v 1.129 2007-05-01 20:00:45 c2woody Exp $ */ +/* $Id: sdlmain.cpp,v 1.130 2007-06-03 10:59:46 c2woody Exp $ */ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -28,6 +28,9 @@ #include #include #include +#ifdef WIN32 +#include +#endif #include "SDL.h" @@ -1303,6 +1306,23 @@ void GFX_Events() { } } +#if defined (WIN32) +static BOOL WINAPI ConsoleEventHandler(DWORD event) { + switch (event) { + case CTRL_SHUTDOWN_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_BREAK_EVENT: + raise(SIGTERM); + return TRUE; + case CTRL_C_EVENT: + default: //pass to the next handler + return FALSE; + } +} +#endif + + /* static variable to show wether there is not a valid stdout. * Fixes some bugs when -noconsole is used in a read only directory */ static bool no_stdout = false; @@ -1355,6 +1375,10 @@ int main(int argc, char* argv[]) { DEBUG_SetupConsole(); #endif +#if defined(WIN32) + SetConsoleCtrlHandler((PHANDLER_ROUTINE) ConsoleEventHandler,TRUE); +#endif + #ifdef OS2 PPIB pib; PTIB tib;