Can member function be run after object destroyed?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Can member function be run after object destroyed?

  1. #1
    Join Date
    Jun 2011
    Posts
    1

    Can member function be run after object destroyed?

    PeekMessage&massege loop in a CView function, then close window. I found the CView is destroyed, but the message loop is still running. How to explain this? That means a member function can be run even the object is released.........

    See following detail?

    In CView, I run a function "OnTestTest"*which is time consuming. So, I put message loop to allow GUI operation. See following code.
    void CtestView::OnTestTest()
    {
    * *BOOL bExit = false ;
    * *MSG msg;
    * *while (!bExit)
    * *{
    * * * while ( (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != FALSE) )
    * * * {
    * * * * * * if ( (msg.message == WM_KEYDOWN)
    * * * * * * && * (msg.wParam *== VK_ESCAPE) )
    * * * * * * {
    * * * * * * * *bExit = true;
    * * * * * * * *break;
    * * * * * * } * *
    * * * * * * *if(msg.message == WM_QUIT)
    * * * * * * {
    * * * * * * * *::PostQuitMessage(0);
    * * * * * * * *bExit = true;
    * * * * * * * *break;
    * * * * * * }
    * * * * * * if (AfxGetApp()->PreTranslateMessage( &msg ) == FALSE)
    * * * * * * {
    * * * * * * * *::TranslateMessage( &msg );
    * * * * * * * *:ispatchMessage( &msg );
    * * * * * * }* * * * * **
    * * * * }
    * * * if(bExit)
    * * * {
    * * * * *break;
    * * * }
    * * * else
    * * * {
    *//// hear is my code........
    * * * }
    * *}
    }
    When*OnTestTest is running,*if I close the program, I found the WM_DESTROY will be sent to windows (::PeekMessage can't retrieve it). Then, the OnDestroy and destruct are run.
    My question is: how this happen that the view is destroyed, but the *CtestView::OnTestTest() is still running? Isn't the CtestView already released?

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: Can member function be run after object destroyed?

    How to explain this?
    Undefined behaviour.

    Also, you can use [code] [/code] tags in the future.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center