BUG: An ASSERT may occur in AfxWndProc when two or more threads display modal dialog boxes in an MFC regular DLL in Visual C++ (177101)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q177101 SYMPTOMS If two or more threads display modal dialog boxes at the
same time inside an MFC regular dynamic-link library (DLL) (USRDLL), the
following ASSERT may be generated in AfxWndProc, on Wincore.cpp, line 365 in
Visual C++ 6.0 (line 368 in Visual C++ 5.0, line 360 in Visual C++ 4.2):
// All other messages route through message map.
CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
ASSERT(pWnd != NULL);
This ASSERT occurs only if one of the threads was created outside of
the DLL. The probability of this problem occurring increases with
the number of threads and modal dialog boxes. CAUSE When AfxGetThread() is called in an MFC regular DLL from a
secondary thread that was not created inside the DLL, it returns the CWinApp
object for the DLL because a CWinThread object was not created for the thread
in the context of the DLL.
When a modal dialog box is displayed,
CWnd::RunModalLoop() pumps messages by calling
AfxGetThread()->PumpMessage(). If two modal dialog boxes both call the
CWinApp object's PumpMessage at the same time, synchronization problems cause
the wrong message to get processed on the wrong thread. RESOLUTION One possible work around is to spawn secondary threads,
which in turn display the modal dialog boxes. Each new thread created inside
the MFC regular DLL will have a new CWinThread object and a separate message
pump. STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
This problem was corrected in Microsoft Visual C++
.NET.
REFERENCES For additional information, please see the following
article(s) in the Microsoft Knowledge Base: 122676INFO:
Multiple Threads and MFC _USRDLLs
| Modification Type: | Major | Last Reviewed: | 6/3/2005 |
|---|
| Keywords: | kbfunctions kbBug kbDlg kbDLL kbNoUpdate kbThread KB177101 kbAudDeveloper |
|---|
|