ATL ASSERT on exit
来源:互联网 发布:h3c f1000管理端口 编辑:程序博客网 时间:2024/06/03 04:38
http://nativemobile.blogspot.com/2008/05/atl-assert-on-exit.html
If you tried the sample code I posted yesterday, you might have seen an elusive ATLASSERT dialog box (in Debug mode, of course). When the assertion fires, it happens when the application is closing and the dialog box is very briefly displayed and then closes. You never get to see what caused the assertion in the first place nor do you get a chance to break into the debugger.
To handle this situation, I changed the ATLASSERT macro definition the following way:
extern void AssertBreakpoint();
#define ATLASSERT(expr) { if(!(expr)) AssertBreakpoint(); /
_ASSERTE(expr); }
When the assertion is triggered, the code first calls the AssertBreakpoint function that is there just for you to place a debugger breakpoint. I implemented it with the following rocket-science code:
void AssertBreakpoint() { int a = 3; }
Now you can run the application and you will be sure that you know where the assertion fired. Why? When the debugger stops on your breakpoint you can immediately check the stack and look at the offending code. In my case the assertion was being fired in the CSlideFormView::PreTranslateMessage method. The form view HWND was already destroyed when the
return CWindow::IsDialogMessage(pMsg);
line was executed and this function validates m_hWnd in debug mode.
So if you find yourself in such a situation, use this technique because by defining your own version of ATLASSERT you essentially "infect" all the ATL and WTL code with your custom implementation. All your ATLASSERT are belong to me.
- ATL ASSERT on exit
- abort(),exit()和assert()
- linux 出错处理: assert abort exit atexit
- 程序中的exit(1)、abort()、assert(0);
- C++异常处理assert,throw,exit用法
- C++异常处理assert,throw,exit用法
- python unit test to assert a method calls sys.exit()
- 出错处理之assert,abort,exit,atexit,strerror
- Linux C 异常处理:绝对异常终止 exit()/abort()、assert()
- Syntax error on token "package", assert expected
- Syntax error on token "package", assert expected
- VBA 巧用 On Error GoTo,Exit Function/Exit Sub,Resume
- First-chance exception in Cairo on exit
- FFmpeg exit code -1073741515 on av_register_all();
- atl
- ATL
- atl
- ATL
- 有哪些集成商是专做BOSS的
- 关于C#操作EXCEL,生成图表的全面应用之一(利用Microsoft.Office.Interop.Excel)
- 进入Ruby on Rails世界
- ISNULL
- MSN、腾讯QQ、SKYPE、阿里巴巴贸易通网页在线客服源代码
- ATL ASSERT on exit
- 评论-支持herock观点:TrackBack不死
- 执行HTTP GET
- Function实现ALV Table 二:ALV的弹出窗口形式
- Google的价值观:10个真理
- Origin of Endian
- 关于vc 打印程序的一些有用代码
- 发布10天 Chrome份额稳定在5-6%之间
- The Anatomy of a Large-Scale Hypertextual Web Search Engine