+// we need a dummy app object if the user doesn't want to create a real one
+class wxDummyConsoleApp : public wxAppConsole
+{
+public:
+ wxDummyConsoleApp() { }
+
+ virtual int OnRun() { wxFAIL_MSG( _T("unreachable code") ); return 0; }
+
+ DECLARE_NO_COPY_CLASS(wxDummyConsoleApp)
+};
+
+// we need a special kind of auto pointer to wxApp which not only deletes the
+// pointer it holds in its dtor but also resets the global application pointer
+wxDECLARE_SCOPED_PTR(wxAppConsole, wxAppPtrBase);
+wxDEFINE_SCOPED_PTR(wxAppConsole, wxAppPtrBase);
+
+class wxAppPtr : public wxAppPtrBase
+{
+public:
+ wxEXPLICIT wxAppPtr(wxAppConsole *ptr = NULL) : wxAppPtrBase(ptr) { }
+ ~wxAppPtr()
+ {
+ if ( get() )
+ {
+ // the pointer is going to be deleted in the base class dtor, don't
+ // leave the dangling pointer!
+ wxApp::SetInstance(NULL);
+ }
+ }
+
+ void Set(wxAppConsole *ptr)
+ {
+ reset(ptr);
+
+ wxApp::SetInstance(ptr);
+ }
+
+ DECLARE_NO_COPY_CLASS(wxAppPtr)
+};
+
+// class to ensure that wxAppBase::CleanUp() is called if our Initialize()
+// fails
+class wxCallAppCleanup
+{
+public:
+ wxCallAppCleanup(wxAppConsole *app) : m_app(app) { }
+ ~wxCallAppCleanup() { if ( m_app ) m_app->CleanUp(); }
+
+ void Dismiss() { m_app = NULL; }
+
+private:
+ wxAppConsole *m_app;
+};
+
+// another tiny class which simply exists to ensure that wxEntryCleanup is
+// always called
+class wxCleanupOnExit