Article ID: 194300 - View products that this article applies to.
This article was previously published under Q194300
When an MFC EXE SDI/MDI application in the context of a command handler calls an exported function in MFC regular DLL, which creates a MFC modal dialog box, the following asserts may be triggered:
If the asserts are ignored, the behavior of the application is normal. The EXE and regular DLL must be dynamically linked to MFC.
ASSERT in wincore.cpp line 884
ASSERT in wincore.cpp line 883
When a parent is not explicitly specified for a modal dialog box, MFC in the PreModal() call determines the parent with a call to CWnd::GetSafeOwner_(). This call returns the routing frame (AfxGetThreadState()->m_pRoutingFrame). m_pRoutingFrame is assigned in a command handler. [See CPushRoutingFrame in CFrameWnd::OnCmdMsg()].
The routing frame is set in the command handler in the EXE, to a frame window of the EXE. Because the thread state is the same in the EXE and the DLL, AfxGetThreadState()->m_pRoutingFrame returns the EXE frame window. A temporary CWnd is created, in the temporary handle map of the DLL, for the routing frame in the CDialog::PreModal() call when calling CWnd::FromHandle(::GetActiveWindow()). This assert, in CWnd::AssertValid(), is caused by the fact that routing frame does not match the temporary CWnd present in the temporary handle map of the regular DLL.
This problem affects all modal windows that are created in a command handler in the context of a regular DLL, where CWnd::GetSafeOwner_() is called. CWnd::GetSafeOwner_() is called during the creation of modal windows. This includes MFC message boxes, OLE property sheets, CDatabase::Connect, dialogs boxes, property sheets, and OLE busy dialog boxes. Note that this problem does not affect modeless windows because CWnd::GetSafeOwner_() is not called in this context.
One workaround is to temporarily set AfxGetThreadState()->m_pRoutingFrame to NULL for the duration of the DoModal() call. The following code can be used:
Another workaround, in the case of dialog boxes and property sheets, is to explicitly set the parent of the dialog box as follows:
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:
(https://support.microsoft.com/kb/194022/ )Visual Studio 6.0 service packs, what, where, why
(https://support.microsoft.com/kb/194295/ )How to tell that a Visual Studio service pack is installed
Steps to Reproduce Behavior
Article ID: 194300 - Last Review: November 21, 2006 - Revision: 3.1