+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)
+{
+#if wxUSE_LOG
+    // Create a non-GUI log target, to be used until GUI (if any) is ready.
+    // Target will be reset by wxAppConsole::Initialize, when GUI logging will work.
+    wxLog::GetActiveTarget();
+#endif
+
+    // 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);
+
+    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(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();
+    }
+}
+