Microsoft Knowledge Base Email Alertz

KBAlertz.com: When you try to display a modal window without explicitly specifying a parent in a command handler of an MFC SDI/MDI application, where the frame window is destroyed in the command handler before displaying the modal window, you might get an assertion...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 193102 - Last Review: August 7, 2007 - Revision: 4.2

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

This article was previously published under Q193102

On This Page

SYMPTOMS

When you try to display a modal window without explicitly specifying a parent in a command handler of an MFC SDI/MDI application, where the frame window is destroyed in the command handler before displaying the modal window, 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 similar to modeless windows. This will also be the case if you update an MFC application from Visual C++ 5.0 to Visual C++ 6.0 (both versions of Visual C++ use the MFC DLL named MFC42.dll).

CAUSE

Modal windows now use the routing frame data member (m_pRoutingFrame) of the thread state to decide on the owner in GetSafeOwner(). The problem is that the CFrameWnd set as the thread state's current routing frame is deleted, but the thread state is not updated to reflect that fact.

RESOLUTION

Set the thread state's current routing frame to NULL in the destructor of your CFrameWnd derived class that is being destroyed:

CMyFrameWnd::~CMyFrameWnd()
   {

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

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in the Visual Studio 6.0 Service Pack 1.

To obtain this service pack, please see:
http://msdn2.microsoft.com/en-us/vstudio/Aa718362.aspx (http://msdn2.microsoft.com/en-us/vstudio/Aa718362.aspx)

MORE INFORMATION

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 code in the destructor for CChildFrame:

CChildFrame::~CChildFrame()
   {

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


(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Bret Bentzinger, Microsoft

REFERENCES

For more information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:
194022  (http://kbalertz.com/Feedback.aspx?kbNumber=194022/ ) Visual Studio 6.0 service packs, what, where, why
194295  (http://kbalertz.com/Feedback.aspx?kbNumber=194295/ ) How to tell that a Visual Studio service pack is installed
193009  (http://kbalertz.com/Feedback.aspx?kbNumber=193009/ ) INFO: Visual Studio 6.0 Service Pack 1 Readme

APPLIES TO
  • Microsoft Foundation Class Library 4.2, when used with:
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbbug kbfix kbqfe kbvs600sp1fix kbvc600sp1fix kbdocview kbvs600sp2fix KB193102
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please