动态生成的CFrameWnd销毁出错。
代码如下:
CTestFrame *pFrame = ( CTestFrame * )CTestFrame::CreateObject();//CTestFrame从CFrameWnd派生
CCreateContext contextT;
contextT.m_pLastView = NULL;
contextT.m_pCurrentFrame = NULL;
contextT.m_pNewDocTemplate = NULL;
contextT.m_pCurrentDoc = NULL;
contextT.m_pNewViewClass = RUNTIME_CLASS( CTestView );
DWORD dwStyle = WS_CHILD|WS_OVERLAPPEDWINDOW|MFS_SYNCACTIVE;
if ( !((CFrameWnd *)pFrame)->Create( NULL, NULL, dwStyle, CRect(0, 0, 0, 0),
pTabCtrl, 0, 0L, &contextT ) )
{
return -1;
}
pFrame->InitialUpdateFrame(NULL, FALSE);
pFrame->ShowWindow(SW_SHOW);
//在pTabCtrl中生成框架
在pTabCtrl销毁的时候销毁框架时候出错 。
错误提示:
test.exe 中的 0x7c22700a (mfc71d.dll) 处未处理的异常: 0xC0000005: 读取位置 0xfeeefeee 时发生访问冲突 。
中断指向文件objcore.cpp中如下行
BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ASSERT(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
// simple SI case
-> CRuntimeClass* pClassThis = GetRuntimeClass();
return pClassThis->IsDerivedFrom(pClass);
}
如果contextT.m_pNewViewClass = RUNTIME_CLASS( CTestView );
改成contextT.m_pNewViewClass = NULL;则不会出错。
谢谢。