PRB: GP Fault From DestroyWindow() Call in VBX EventLast reviewed: July 17, 1997Article ID: Q99846 |
1.00 1.50
WINDOWS
kbprg kbprb
The information in this article applies to:
SYMPTOMSIf an application calls the DestroyWindow() function in a VBX control event handler, a general protection (GP) fault occurs.
CAUSEThe application attempts to destroy the VBX control while processing a VBX event.
RESOLUTIONEdit 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); MORE INFORMATIONThis 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.
Message Map
BEGIN_MESSAGE_MAP(CMyDialog, CDialog) //{{AFX_MSG_MAP(CMyDialog) ON_VBXEVENT(VBN_CLICK, IDC_COMMAND3D, OnClickCancel) //}}AFX_MSG_MAP END_MESSAGE_MAP() Event Handler
void CMyDialog::OnClickCancel(UINT, int, CWnd* pControl, LPVOID){ DestroyWindow(); // this call causes a protection violation // PostMessage(WM_CLOSE); // this call does not}
|
Additional reference words: 1.00 1.50 2.00 2.50 crash
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |