问m_pCtrlSite对MFC从Debug版到Release版的影响?
rice 2002-09-16 11:34:39 用MFC编写程序在Debug版下,工作正常,但是在Release版出错。
出错消息为:
Unhandled exception in PS.exe(MFC42.dll): 0xC0000005:Access Violation.
程序细节:
使用DoModal()打开一个对话框,在对话框OnInitDialog中生成一个工作线程,通过工作线程向对话框发送定制消息,对话框在受到消息后调用CDialog::OnOK()关闭自己。
调试结果:
发现消息传送在Debug和Release下,都正常。
出错发生在CWnd::SetWindowPos函数中,该函数被CDialog::DoModal调用。
分别在Debug和Release下调试发现,
BOOL CWnd::SetWindowPos(const CWnd* pWndInsertAfter, int x, int y, int cx,
int cy, UINT nFlags)
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlSite == NULL)
return ::SetWindowPos(m_hWnd, pWndInsertAfter->GetSafeHwnd(),//debug mode excute
x, y, cx, cy, nFlags);
else
return m_pCtrlSite->SetWindowPos(pWndInsertAfter, x, y, cx, cy, nFlags);//release mode excute
}
在Debug版下,执行了if的上句;Release版下,执行了if的下句。也就是说MFC对m_pCtrlSite设了不同的值?
于是,我在调用OnOK()前,加上m_pCtrlSite=0。但是m_pCtrlSite 仍然为0x66。
我也怀疑是heap的问题,分别在工作线程发消息前和对话框收消息后调用
if(_heapchk()!=_HEAPOK) {
::MessageBox(0, "heap", "heap", MB_ICONERROR);
DebugBreak();
}
但是两个版本都没有报错。
请教解决办法;或建立模式对话框由另一个线程关闭的方法。