CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: OnAppExit()

  1. #1
    Join Date
    Apr 1999
    Posts
    51

    OnAppExit()



    What is the default action for the Application exit? I tried creating a message map for OnAppExit to perform some checking and cleanup. Everything worked except the applicaiton did not exit. So, I added exit(0) to the end of the function. In debug mode, everything works fine but in release mode I get an exception and the program crashes. I disabled the function and message map and the program exists without any problem in release or debug. What should I call to terminate the application when overriding the AppExit()?


    Thanks,


    Steve

  2. #2
    Join Date
    Apr 1999
    Posts
    24

    Re: OnAppExit()



    The CWinApp default handler does:


    void CWinApp::OnAppExit()

    {

    // same as double-clicking on main window close box

    ASSERT(m_pMainWnd != NULL);

    m_pMainWnd->SendMessage(WM_CLOSE);

    }


    Explicitly calling this from your overridden handler should work fine, although I might like to suggest that you do your stuff in an override of CWinApp::ExitInstance() or the even the destructor of your Application object.

  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: OnAppExit()



    Are you calling the base class implementation at the end of your override?


    void MyApp::OnAppExit()

    {

    // do cleanup

    ...

    CWinApp::OnAppExit(); // call base class implementation

    }


    Dave

  4. #4
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: OnAppExit()



    Do NOT use exit(0) from a Windows application

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured