Hello Everybody,
I am having a very strange problem with one of my modalless dialog and it crashes.
Actually what i have done is created a modelless dialog as follows:
CDlgVbRecAvail* pDlg = CDlgVbRecAvail::GetDlgInstance();
if( pDlg->m_hWnd != NULL )
{
pDlg->ShowWindow(SW_RESTORE);
pDlg->SetFocus();
}
else
{
pDlg->CDialog::Create(CDlgVbRecAvail::IDD, this);
}
pDlg->ShowWindow(SW_SHOW);
where
CDlgVbRecAvail::GetDlgInstance()
is defined as follows:
CDlgVbRecAvail* CDlgVbRecAvail::GetDlgInstance()
{
if( m_pDlgInst == NULL )
m_pDlgInst = new CDlgVbRecAvail();
else
return m_pDlgInst;
return m_pDlgInst;
}
and
m_pDlgInst
is declared in the header file as follows:
static CDlgVbRecAvail* m_pDlgInst;
Now i have one
CDialog
method
OnCancel
and is as follows:
void CDlgVbRecAvail::OnCancel()
{
DestroyWindow();
}
and one Method overriding
PostNcDestroy
and is as follows
void CDlgVbRecAvail::PostNcDestroy()
{
delete this;
}
Now the problem arises when I close the dialog it crashes after the call to
DestroyWindow
in
OnCancel
method.
PostNcDestroy
is not being called.
it show the following dialog
http://www.imghack.se/126142[
^]
and then breaks in to this class
dbgheap.c
in the code at line no. 2103
extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
const void * pUserData
)
{
#ifndef WINHEAP
int i;
void * base;
#else /* WINHEAP */
#endif /* WINHEAP */
if (!pUserData)
return FALSE;
if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
return FALSE;
#ifdef WINHEAP
#ifndef _WIN64
if ( __active_heap == __V6_HEAP )
{
PHEADER pHeader;
if (pHeader = __sbh_find_block(pHdr(pUserData)))
{
return __sbh_verify_block(pHeader, pHdr(pUserData));
}
else
return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
#ifdef CRTDLL
else if ( __active_heap == __V5_HEAP )
{
__old_sbh_region_t * preg;
__old_sbh_page_t * ppage;
__old_page_map_t * pmap;
if ( (pmap = __old_sbh_find_block( pHdr(pUserData), &preg, &ppage )) !=
NULL )
{
if ( *pmap )
return TRUE;
else
return FALSE;
}
else
return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
#endif /* CRTDLL */
else #endif /* _WIN64 */
{
return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
#else /* WINHEAP */
for (i = 0; (base = _heap_regions[i]._regbase) != NULL &&
i < _HEAP_REGIONMAX; i++)
{
if (pUserData >= base && pUserData <
(void *)(((char *)base)+_heap_regions[i]._currsize))
return TRUE;
}
return FALSE;
#endif /* WINHEAP */
}
Please help me in getting rid of this crash...
Thank you all.