+ wxTheApp = NULL;
+ }
+
+
+ DoCommonPostCleanup();
+
+ // check for memory leaks
+#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
+ if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
+ {
+ wxLogDebug(wxT("There were memory leaks.\n"));
+ wxDebugContext::Dump();
+ wxDebugContext::PrintStatistics();
+ }
+#endif // Debug
+
+}
+
+// ----------------------------------------------------------------------------
+// wxEntry
+// ----------------------------------------------------------------------------
+
+#if !defined(__WXMSW__) || !wxUSE_ON_FATAL_EXCEPTION
+ #define wxEntryReal wxEntry
+#endif // !(__WXMSW__ && wxUSE_ON_FATAL_EXCEPTION)
+
+int wxEntryReal(int& argc, wxChar **argv)
+{
+ // library initialization
+ if ( !wxEntryStart(argc, argv) )
+ {
+ return -1;
+ }
+
+ // if wxEntryStart succeeded, we must call wxEntryCleanup even if the code
+ // below returns or throws
+ wxCleanupOnExit cleanupOnExit;
+
+ WX_SUPPRESS_UNUSED_WARN(cleanupOnExit);
+
+ // app initialization
+ if ( !wxTheApp->CallOnInit() )
+ {
+ // don't call OnExit() if OnInit() failed
+ return -1;
+ }
+
+ // app execution
+ int retValue = wxTheApp->OnRun();
+
+ // why should we do this? it doesn't close all window, just one of them and
+ // this shouldn't be necessary anyhow...
+#if 0
+ // close any remaining windows
+ wxWindow *topWindow = wxTheApp->GetTopWindow();
+ if ( topWindow )
+ {
+ // forcibly delete the window.
+ topWindow->Destroy();
+
+ // collect the dead objects
+ wxTheApp->DeletePendingObjects();
+ }
+#endif // 0
+
+ // app clean up
+ wxTheApp->OnExit();
+
+ return retValue;
+}
+
+// wrap real wxEntry in a try-except block to be able to call
+// OnFatalException() if necessary
+#if defined(__WXMSW__) && wxUSE_ON_FATAL_EXCEPTION
+
+extern unsigned long wxGlobalSEHandler();
+
+int wxEntry(int& argc, wxChar **argv)
+{
+ __try
+ {
+ return wxEntryReal(argc, argv);
+ }
+ __except ( wxGlobalSEHandler() )
+ {
+ ::ExitProcess(3); // the same exit code as abort()
+
+#if !defined(_MSC_VER) || _MSC_VER < 1300
+ // this code is unreachable but put it here to suppress warnings
+ // from some compilers
+ return -1;
+#endif
+ }
+}
+
+#endif // __WXMSW__ && wxUSE_ON_FATAL_EXCEPTION
+
+#if wxUSE_UNICODE
+
+// as with wxEntryStart, we provide an ANSI wrapper
+int wxEntry(int& argc, char **argv)
+{
+ ConvertArgsToUnicode(argc, argv);
+
+ return wxEntry(argc, gs_initData.argv);
+}
+
+#endif // wxUSE_UNICODE
+
+// ----------------------------------------------------------------------------
+// wxInitialize/wxUninitialize
+// ----------------------------------------------------------------------------
+
+bool wxInitialize(int argc, wxChar **argv)
+{
+ wxCRIT_SECT_LOCKER(lockInit, gs_initData.csInit);
+
+ if ( gs_initData.nInitCount++ )
+ {
+ // already initialized
+ return true;
+ }
+
+ return wxEntryStart(argc, argv);
+}
+
+void wxUninitialize()
+{
+ wxCRIT_SECT_LOCKER(lockInit, gs_initData.csInit);
+
+ if ( !--gs_initData.nInitCount )
+ {
+ wxEntryCleanup();