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: