You are currently offline, waiting for your internet to reconnect

FIX: Assert in Appui1.cpp Line 215 in MFC SDI/MDI application

This article was previously published under Q193102
This article has been archived. It is offered "as is" and will no longer be updated.
When you try to display a modal window without explicitly specifying aparent in a command handler of an MFC SDI/MDI application, where the framewindow is destroyed in the command handler before displaying the modalwindow, you might get an assertion in CCmdTarget::GetRoutingFrame_()(Appui1.cpp line: 215) with debug builds.

In the release builds of the application, modal windows may behave similarto modeless windows. This will also be the case if you update an MFCapplication from Visual C++ 5.0 to Visual C++ 6.0 (both versions of Visual C++ use the MFC DLLnamed MFC42.dll).
Modal windows now use the routing frame data member (m_pRoutingFrame) ofthe thread state to decide on the owner in GetSafeOwner(). The problem isthat the CFrameWnd set as the thread state's current routing frameis deleted, but the thread state is not updated to reflect that fact.
Set the thread state's current routing frame to NULL in the destructor ofyour CFrameWnd derived class that is being destroyed:

CMyFrameWnd::~CMyFrameWnd()   {      if( AfxGetThreadState()->m_pRoutingFrame == this )      {         AfxGetThreadState()->m_pRoutingFrame = NULL;      }   }				
Microsoft has confirmed this to be a bug in the Microsoft products listedat the beginning of this article. This bug has been fixed in the VisualStudio 6.0 Service Pack 1.

To obtain this service pack, please see:
The MFC frame windows affected by this problem can be of type CFrameWnd,CMDIFrameWnd, CMDIChildWnd, and COleIPFrameWnd.

The MFC modal windows affected are:
  • Dialog
  • CPropertySheet
  • Ole Property Sheet [invoked through [ASCII 150] OleObject::DoVerb(OLEIVERB_PROPERTIES)]
  • COleBusyDialog
  • Message Box [invoked through AfxMessageBox()]
  • MAPI modal window [when calling MAPISendMail()]
  • SQL Driver Connection dialog box [when calling SQLDriverConnect()]

Steps to Reproduce Behavior

  1. Use AppWizard to generate an MFC exe that is an MDI-based application.
  2. Use ClassWizard to override OnCloseDocument of the CDocument class generated by AppWizard.
  3. Edit the OnCloseDocument member function as shown here:
          void CMyDoc::OnCloseDocument()      {         CDocument::OnCloseDocument();         AfxMessageBox("The Document is Closed");      }					
  4. Build and run the application.
  5. On the File menu, click Close.
RESULTS: The following error appears:
"Debug Assertion Failed! File:Appui1.cpp line: 215".
To correct this problem in the case mentioned above, add the following codein the destructor for CChildFrame:

CChildFrame::~CChildFrame()   {      if( AfxGetThreadState()->m_pRoutingFrame == this )      {         AfxGetThreadState()->m_pRoutingFrame = NULL;      }   }				

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by BretBentzinger, Microsoft
For more information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:
194022 Visual Studio 6.0 service packs, what, where, why
194295 How to tell that a Visual Studio service pack is installed
193009 INFO: Visual Studio 6.0 Service Pack 1 Readme
connect MfcDocView

Article ID: 193102 - Last Review: 02/28/2014 04:16:59 - Revision: 4.2

Microsoft Foundation Class Library 4.2

  • kbnosurvey kbarchive kbbug kbfix kbqfe kbvs600sp1fix kbvc600sp1fix kbdocview kbvs600sp2fix KB193102