FIX: The CDialog::Create() function returns an incorrect value when a dialog box is created in Visual C++ (193099)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Learning Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.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 Q193099 SYMPTOMS If a dialog box is created via the CDialog::Create() call,
and the dialog box's OnInitDialog() (in response to WM_INITDIALOG message) ends
the dialog box via EndDialog(), the CDialog::Create() function returns a
non-zero value. The CDialog::Create() in this case should return zero.
Because the dialog box was destroyed due to an EndDialog() call in
the dialog's OnInitDialog(), CDialog::m_hWnd is NULL in this case.
CAUSE An additional test was made in the WM_INITDIALOG code (at
line 365 of Dlgcore.cpp), which leads to Create() succeeding even if the window
handle is NULL. MFC code for Visual C++ 5.0:
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,
CWnd* pParentWnd, HINSTANCE hInst)
{
// ...
if (hWnd == NULL)
{
// ...
// .. dump some debug information
return FALSE;
}
ASSERT(hWnd == m_hWnd);
return TRUE;
}
MFC code for Visual C++ 6.0:
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,
CWnd* pParentWnd, HINSTANCE hInst)
{
// ...
// Help with error diagnosis (only if WM_INITDIALOG didn't
// EndDialog())
if (hWnd == NULL && (m_nFlags & WF_CONTINUEMODAL)) // <--- PROBLEM!!!
{
// ... dump some debug information.
return FALSE;
}
ASSERT(hWnd == m_hWnd);
return TRUE;
}
RESOLUTION When calling CDialog::Create check both the return value of
CDialog::Create(), and the value of CDialog::m_hWnd. If CDialog::m_hWnd is
NULL, then the dialog-box creation is unsuccessful. 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: For more information on the Visual Studio 6.0 Service Pack 1,
please see the following articles in the Microsoft Knowledge Base:
Modification Type: | Major | Last Reviewed: | 4/20/2006 |
---|
Keywords: | kbfunctions kbQFE kbBug kbDlg kbfix kbNoUpdate kbVC600SP1Fix kbVS600SP1fix KB193099 kbAudDeveloper |
---|
|