VC6.0常见错误之::Debug Assertion Failed!
来源:互联网 发布:社保网络认证的意义 编辑:程序博客网 时间:2024/06/05 09:59
初学者编程常遇到的断言错误,最近遇到比较多,在此整理,方便以后查阅。
绝大部分内容来自topic.csdn.net论坛,在此感谢各位大牛的解答,感谢各位大牛的指点!~
本文将不断更新。
下面进入正题:
1、VC6.0常见错误之:Debug Assertion Failed!在winocc.cpp第301行错误
断言错误,如图:
找到winocc中的源代码如下:
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);}
错误原因分析:
下面是我原来的写法,导致错误:
BOOL CDlgControlPanel::HideAll(){this->m_pDlgReport = new CDlgReport;this->m_pDlgReport->Create(CDlgReport::IDD,this);this->m_pDlgReport->ShowWindow(SW_SHOW);}解决方法:
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对应的控件不存在
估计删除了界面上的控件,但是没有删除其映射关系
以下是出现断言错误的地方
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行
错误源代码如下:
// 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行
错误源代码如下:
_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类前,问题解决。
感谢fyz2841585,来自http://topic.csdn.net/u/20101228/10/c1701227-f5b9-4cd7-8701-dcb52c7c8b85.html
- VC6.0常见错误之::Debug Assertion Failed!
- VC6.0常见错误之::Debug Assertion Failed!
- vc6.0 中Debug assertion failed的错误解决
- 错误:Debug assertion failed
- vc 错误:Debug Assertion Failed
- Debug Assertion Failed 错误定位
- Debug Assertion Failed! 错误解析
- 抛出错误Debug Assertion Failed!
- Debug Assertion Failed错误如何消除
- C/C++出现Debug Assertion Failed!错误
- 有些情况下vc6.0 MFC程序运行时出现Debug Assertion Failed 的解决方法
- MFC学习笔记之VC++ Debug Assertion Failed! 错误(File: strex.cpp Line: 690)
- Debug Assertion Failed
- debug assertion failed
- Debug Assertion Failed解决方法! !!
- Debug Assertion Failed!
- Debug Assertion Failed!
- debug assertion failed
- 如何解决 "Unable to start debugging" ?
- perl 内置变量 $1
- Perl内置及特殊变量
- Android多媒体支撑库OpenCore视频硬件加速
- android学习——Activity生命周期小谈
- VC6.0常见错误之::Debug Assertion Failed!
- 30个最常用CSS选择器解析
- linux下tree指令的用法
- 使用正则表达式判断合法的电话号码
- exp/imp 资料
- Monkey stress-test tool
- shell编程范例之字符串操作[转]
- Java Overview
- 在VC++中用ODBC访问SQL Server数据库