PRB: GP Fault From DestroyWindow() Call in VBX EventID: Q99846
|
If an application calls the DestroyWindow() function in a VBX control event handler, a general protection (GP) fault occurs.
The application attempts to destroy the VBX control while processing a VBX event.
Edit the code to remove the DestroyWindow() call. Instead, post a WM_CLOSE message to the appropriate dialog box or control with the following code:
PostMessage(WM_CLOSE);
This error typically occurs if a modeless dialog box contains a VBX
control as a Cancel button and the event handler calls DestroyWindow()
to terminate the dialog box.
The code example below is a sample dialog box message map and VBX
event handler that demonstrate the problem. The message map processes
a VBN_CLICK event from a 3D pushbutton VBX control. When the event
occurs, the code calls the CMyDialog::OnClickCancel() handler. If the
handler calls the DestroyWindow() function, a GP fault occurs.
Replacing the DestroyWindow() call with a PostMessage() call
eliminates this problem.
The PostMessage() call allows the application to finish processing the
event before destroying the dialog box and VBX control.
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_VBXEVENT(VBN_CLICK, IDC_COMMAND3D, OnClickCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CMyDialog::OnClickCancel(UINT, int, CWnd* pControl, LPVOID)
{
DestroyWindow(); // this call causes a protection violation
// PostMessage(WM_CLOSE); // this call does not
}
Additional query words: 1.00 1.50 2.00 2.50 crash
Keywords : kb16bitonly
Version :
Platform :
Issue type :
Last Reviewed: July 26, 1999