+void wxEntryCleanup()
+{
+ DoCommonPreCleanup();
+
+
+ // delete the application object
+ if ( wxTheApp )
+ {
+ wxTheApp->CleanUp();
+
+ delete wxTheApp;
+ wxApp::SetInstance(NULL);
+ }
+
+
+ DoCommonPostCleanup();
+}
+
+// ----------------------------------------------------------------------------
+// wxEntry
+// ----------------------------------------------------------------------------
+
+// for MSW the real wxEntry is defined in msw/main.cpp
+#ifndef __WXMSW__
+ #define wxEntryReal wxEntry
+#endif // !__WXMSW__
+
+int wxEntryReal(int& argc, wxChar **argv)
+{
+ // library initialization
+ if ( !wxEntryStart(argc, argv) )
+ {
+#if wxUSE_LOG
+ // flush any log messages explaining why we failed
+ delete wxLog::SetActiveTarget(NULL);
+#endif
+ return -1;
+ }
+
+ // if wxEntryStart succeeded, we must call wxEntryCleanup even if the code
+ // below returns or throws
+ wxCleanupOnExit cleanupOnExit;
+
+ WX_SUPPRESS_UNUSED_WARN(cleanupOnExit);
+
+ wxTRY
+ {
+
+ // app initialization
+ if ( !wxTheApp->CallOnInit() )
+ {
+ // don't call OnExit() if OnInit() failed
+ return -1;
+ }
+
+ // ensure that OnExit() is called if OnInit() had succeeded
+ class CallOnExit
+ {
+ public:
+ ~CallOnExit() { wxTheApp->OnExit(); }
+ } callOnExit;
+
+ WX_SUPPRESS_UNUSED_WARN(callOnExit);
+
+ // app execution
+ return wxTheApp->OnRun();
+ }
+ wxCATCH_ALL( wxTheApp->OnUnhandledException(); return -1; )
+}
+
+#if wxUSE_UNICODE
+
+// as with wxEntryStart, we provide an ANSI wrapper
+int wxEntry(int& argc, char **argv)
+{
+ ConvertArgsToUnicode(argc, argv);
+
+ return wxEntry(gs_initData.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 == 0 )
+ {
+ wxEntryCleanup();
+ }
+}