-// May wish not to have a DllMain or WinMain, e.g. if we're programming
-// a Netscape plugin or if we're writing a console application
-#if wxUSE_GUI && !defined(NOMAIN)
+// wrap real wxEntry in a try-except block to be able to call
+// OnFatalException() if necessary
+#if wxUSE_ON_FATAL_EXCEPTION && wxUSE_BASE
+
+// global pointer to exception information, only valid inside OnFatalException,
+// used by wxStackWalker and wxCrashReport
+extern EXCEPTION_POINTERS *wxGlobalSEInformation = NULL;
+
+// flag telling us whether the application wants to handle exceptions at all
+static bool gs_handleExceptions = false;
+
+unsigned long wxGlobalSEHandler(EXCEPTION_POINTERS *pExcPtrs)
+{
+ if ( gs_handleExceptions && wxTheApp )
+ {
+ // store the pointer to exception info
+ wxGlobalSEInformation = pExcPtrs;
+
+ // give the user a chance to do something special about this
+ __try
+ {
+ wxTheApp->OnFatalException();
+ }
+ __except ( EXCEPTION_EXECUTE_HANDLER )
+ {
+ // nothing to do here, just ignore the exception inside the
+ // exception handler
+ ;
+ }
+
+ wxGlobalSEInformation = NULL;
+
+ // this will execute our handler and terminate the process
+ return EXCEPTION_EXECUTE_HANDLER;
+ }
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}