VC6.0常见错误之::Debug Assertion Failed!
2013-08-27 11:20
295 查看
VC6.0常见错误之::Debug Assertion Failed!
1、VC6.0常见错误之:Debug Assertion Failed!在winocc.cpp第301行错误断言错误,如图:
找到winocc中的源代码如下:
[cpp] view
plaincopy
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));//错误在此
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
错误原因分析:
下面是我原来的写法,导致错误:
[cpp] view
plaincopy
BOOL CDlgControlPanel::HideAll()
{
this->m_pDlgReport = new CDlgReport;
this->m_pDlgReport->Create(CDlgReport::IDD,this);
this->m_pDlgReport->ShowWindow(SW_SHOW);
}
解决方法:
[cpp] view
plaincopy
BOOL CDlgControlPanel::HideAll()
{
this->m_pDlgReport = new CDlgReport;
this->m_pDlgReport->Create(CDlgReport::IDD,this);
::ShowWindow(this->m_pDlgReport->m_hWnd, SW_SHOW);
}
区别就在于调用ShowWindow的方式。
真正原因是什么呢,是因为API传进去的句柄是这个控件的句柄,即控件->m_hWnd,而MFC传进去的句柄是此类(即CDlgReport类)的句柄,即this->m_hWnd。还有一点需要注意的是,可能在Release版本有时会运行正常,就侥幸这样用了,其实不管是Release版本还是Debug版本,都必须用上面的办法处理,如果你要控制某一个控件,那么你就传它对应的句柄,不要传别人的句柄进去。
感谢“C++帮助文档”的博客:http://hi.baidu.com/vc_net/blog/item/0fc01f307812d580a8018e2c.html
2、VC6.0常见错误之:Debug Assertion Failed!在dlgdata.cpp第43行错误
对话框中某个ID对应的控件不存在
估计删除了界面上的控件,但是没有删除其映射关系
以下是出现断言错误的地方
[cpp] view
plaincopy
HWND CDataExchange::PrepareCtrl(int nIDC)
{
ASSERT(nIDC != 0);
ASSERT(nIDC != -1); // not allowed
HWND hWndCtrl;
m_pDlgWnd-> GetDlgItem(nIDC, &hWndCtrl);
if (hWndCtrl == NULL)
{
TRACE1( "Error: no data exchange control with ID 0x%04X.\n ", nIDC);
ASSERT(FALSE); //错误在此
AfxThrowNotSupportedException();
}
m_hWndLastControl = hWndCtrl;
m_bEditLastControl = FALSE; // not an edit item by default
ASSERT(hWndCtrl != NULL); // never return NULL handle
return hWndCtrl;
}
感谢vocanicy,来自http://topic.csdn.net/u/20070919/18/98a3444e-ff9b-4f7b-acb5-a35783379376.html
3、VC6.0常见错误之:Debug Assertion Failed!在winctrl1.cpp在184行
错误源代码如下:
[cpp] view
plaincopy
// Derived class is responsible for implementing these handlers
// for owner/self draw controls (except for the optional DeleteItem)
void CComboBox::DrawItem(LPDRAWITEMSTRUCT)
{ ASSERT(FALSE); }//错误在此
void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
{ ASSERT(FALSE); }
int CComboBox::CompareItem(LPCOMPAREITEMSTRUCT)
{ ASSERT(FALSE); return 0; }
void CComboBox::DeleteItem(LPDELETEITEMSTRUCT)
{ /* default to nothing */ }
错误指向CComboBox控件不能绘制。当时我遇到的问题原因是,我把这个控件当做自定义MyComboBox类使用,但在声明的时候忘了修改类型,导致报错。
解决方法只要在头文件中修改控件类型就行了。
其实关于winctrl1.cpp,很多类似的错误也一样的。都是控件类型搞错。
4、VC6.0常见错误之:afxwin2.inl第126行
错误源代码如下:
[cpp] view
plaincopy
_AFXWIN_INLINE void CWnd::Invalidate(BOOL bErase)
{
ASSERT(::IsWindow(m_hWnd));\\错误在此
::InvalidateRect(m_hWnd, NULL, bErase);
}
看到IsWindow就明白了吧,是空句柄!也就是该对话框还未创建。
我遇到的情况是,A类的Clear函数中调用了this->Invalidate();,而B类调用了A类的Clear函数,此时A类还未实例化,所以A类句柄为空,m_hWnd = NULL。我的解决方法是将A类的实例化放在B类前,问题解决。
相关文章推荐
- VC6.0常见错误之::Debug Assertion Failed!
- VC Debug Assertion failed错误常见原因分析
- 错误提示: Debug Assertion Failed! Program:... File:fclose.c Expression: (stream!=NULL)
- 错误:Debug assertion failed
- 抛出错误Debug Assertion Failed!
- GID/GDI+ 的运行时错误 Debug Assertion Failed Expression m_hDC==0
- Debug Assertion Failed! 错误解决 (关于文件文件写入程序)
- c++ occcont.cpp line 925运行错误 Debug Assertion Failed
- 有些情况下vc6.0 MFC程序运行时出现Debug Assertion Failed 的解决方法
- 打开IE时弹出Debug Assertion Failed!错误问题
- 关于 debug assertion failed, file:dlgdata.cpp,line"43 错误解析
- VC++常规错误之21:Debug Assertion Failed!在winocc.cpp第307或329行错误
- 关于 debug assertion failed, file:dlgdata.cpp,line"44 错误收藏
- MFC学习笔记之VC++ Debug Assertion Failed! 错误(File: strex.cpp Line: 690)
- MFC程序出现“Debug Assertion Failed! File:dlgdata.cpp Line: 43 ”错误
- Debug Assertion Failed错误如何消除
- VC错误: debug assertion failed; file dlgdata.cpp; line43
- MFC程序出现“Debug Assertion Failed! File:dlgdata.cpp Line: 43 ”错误
- 抛出错误Debug Assertion Failed!
- MFC Debug Assertion Failed 错误