Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1683575
  • 博文数量: 347
  • 博客积分: 9328
  • 博客等级: 中将
  • 技术积分: 2680
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-29 23:45
文章分类

全部博文(347)

文章存档

2016年(1)

2013年(4)

2012年(207)

2011年(85)

2010年(50)

分类: C/C++

2012-06-11 16:02:59

原文:

I have a code that is called on a pointer that may be invalid (I have no control over its value):

 

__try { CString str = (LPCTSTR)wParam; //Work with 'str' now } __except(1) { //Memory fault }

 

But when I try to use it in a MFC project, it gives me this error:

error C2712: Cannot use __try in functions that require object unwinding

 

 

解决方法:

__try
{
  DoStuffWithWParam(wParam);
}
__except(1)
{
  //Memory fault
}

void DoStuffWithWParam(WPARAM wParam) {

CString str = (LPCTSTR)wParam;

  //Work with 'str' now
}

阅读(2872) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~