I am getting the following debug assertion on closing of the application :
I have debugged the flow and found that the assertion is happening in CWnd::DestroyWindow()
// Should have been detached by OnNcDestroy
#ifdef _DEBUG
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
My class is derived from COleControl which in turn is derived from CWnd.
The object creation is happening in .NET winform and on Closing of application the object destructor is getting called and the assert is coming.
Things I have tried :
1) Calling DestroyWindow() on my class destructor : didnt work
2) Overridden OnFinalRelease like below and it worked :
void CSimple::OnFinalRelease()
{
if (!m_bFinalReleaseCalled)
{
m_bFinalReleaseCalled = TRUE;
ReleaseCaches();
CWnd::OnNcDestroy(); --> explicitly called OnNcDestroy()
if (m_hWnd != NULL)
DestroyWindow();
CCmdTarget::OnFinalRelease();
}
I am not sure whether this is proper fix. I am also not sure whether the issue is in .NET side.