Skip to content

WxEntry

wxEntryReal

내부 구현은 src/common/init.cpp파일의 wxEntryReal함수에 존재한다.

int wxEntryReal(int& argc, wxChar **argv)
{
    // library initialization
    wxInitializer initializer(argc, argv);

    if ( !initializer.IsOk() )
    {
#if wxUSE_LOG
        // flush any log messages explaining why we failed
        delete wxLog::SetActiveTarget(NULL);
#endif
        return -1;
    }

    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; )
}

Custom Main

First version

wxIMPLEMENT_WX_THEME_SUPPORT;
wxIMPLEMENT_APP_NO_MAIN(SzdbApp);

int runSzdbApp(int argc, char ** argv)
{
#if wxUSE_UNICODE && defined(__VISUALC__)
    // TODO: mbstowcs
#endif
    wxDISABLE_DEBUG_SUPPORT();
    return wxEntry(argc, argv);
}

Second version

wxIMPLEMENT_WX_THEME_SUPPORT;

static int runCyclops(int argc, wxChar ** argv)
{
    int const ERROR_CODE = -1;

    wxDISABLE_DEBUG_SUPPORT();
    wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "Cyclops");
    wxApp::SetInstance(new MugcupApp());
    wxEntryStart(argc, argv);

    int result = ERROR_CODE;

    try {
        // app initialization.
        if (!wxTheApp->CallOnInit() != false) {
            // don't call OnExit() if OnInit() failed
            return -1;
        }

        // app execution.
        result = wxTheApp->OnRun();
        wxTheApp->OnExit();
    } catch (...) {
        wxTheApp->OnUnhandledException();
        result = ERROR_CODE;
    }

    wxEntryCleanup();
    return result;
}

int mugRunCyclopsA(int argc, char ** argv)
{
#if wxUSE_UNICODE && defined(__VISUALC__)
    return -1;
#else
    return runCyclops(argc, argv);
#endif
}

int mugRunCyclopsW(int argc, wchar_t ** argv)
{
#if wxUSE_UNICODE && defined(__VISUALC__)
    return runCyclops(argc, argv);
#else
    return -1;
#endif
}

See also