DestroyWindow ASSERT problem....strange, strange!

DestroyWindow ASSERT problem....strange, strange!

Post by Patanis » Sat, 17 Jun 2006 06:39:06


Hi

I have derived a dialog-class in a DLL (shared MFC)
I can construct an object of this class in my app, and when overloading

DoModal() and adding an AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
call, I can see the CMyDialog dialog.

But here is the issue, I have a timer set for a certain time, it posts
a message and the dialog has to be killed - so I use CDialog::OnCancel.

Then DoModal calls DestroyWindow() -
Here a copy of the m_hWnd is made in hWndOrig.
#ifdef _DEBUG
hWndOrig = m_hWnd;
#endif

Then m_hWnd gets set to Null by ::DestroyWndow (which calls
OnNcDestroy).
But later in DestroyWindow itself, there is a check:
#ifdef _DEBUG
ASSERT(m_hWnd == hWndOrig);
#endif

And the program asserts here, which is expected as the ::DestroyWindow
call before this set the m_hWnd to NULL......this is strange!

Please advise, I saw similar queries posted before, but no answers..I
have pasted the Wincore.cpp DestroyWindow() code below for reference...

Thanks!


if (m_hWnd != NULL)
{
pMap = afxMapHWND();
ENSURE(pMap != NULL);
pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
#ifdef _DEBUG
hWndOrig = m_hWnd;
#endif
}

#ifdef _AFX_NO_OCC_SUPPORT
if (m_hWnd != NULL)
bResult = ::DestroyWindow(m_hWnd);
#else //_AFX_NO_OCC_SUPPORT
if ((m_hWnd != NULL) || (m_pCtrlSite != NULL))
{
if (m_pCtrlSite == NULL)
bResult = ::DestroyWindow(m_hWnd);
else
bResult = m_pCtrlSite->DestroyControl();
}
#endif //_AFX_NO_OCC_SUPPORT

if (hWndOrig != NULL)
{
// Note that 'this' may have been deleted at this point,
// (but only if pWnd != NULL)
if (pWnd != NULL)
{
// Should have been detached by OnNcDestroy
#ifdef _DEBUG
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
#endif
}
else
{
#ifdef _DEBUG
ASSERT(m_hWnd == hWndOrig);
#endif
// Detach after DestroyWindow called just in case
Detach();
}
 
 
 

DestroyWindow ASSERT problem....strange, strange!

Post by Ajay Kalr » Sat, 17 Jun 2006 11:31:50


What sort of DLL is it? Regular or MFC Extension? You should not use
AFX_MANAGE_STATE in a MFC Extension DLL.


Is this the cause of it? In your OnClose, you should destroy the timer.


---
Ajay

 
 
 

DestroyWindow ASSERT problem....strange, strange!

Post by Patanis » Sat, 17 Jun 2006 14:29:12

The KillTimer() is called before the Dialog::OnCancel.
I believe the problem is not with the timer, but with dialog window
handles?

Please advise. Has anyone has encountered similar problem with
DestroyWindow....
Thanks.
 
 
 

DestroyWindow ASSERT problem....strange, strange!

Post by Ajay Kalr » Sat, 17 Jun 2006 19:45:39

> Please advise. Has anyone has encountered similar problem with

No. This is MFC code and is called each time a modal dialog is
destroyed. You must be doing something different. You did not answer
about type of DLL this is.

---
Ajay