error C2712: Cannot use __try in functions that require object unwinding_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > error C2712: Cannot use __try in functions that require object unwinding

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

 2012/6/11 0:14:21  aigo  程序员俱乐部  我要评论(0)
  • 摘要:原文:http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/42985583-36fb-4e14-8642-bd837aac0727Ihaveacodethatiscalledonapointerthatmaybeinvalid(Ihavenocontroloveritsvalue):__try{CStringstr=(LPCTSTR)wParam;//Workwith'str'now}__except(1)
  • 标签:can function not

原文:http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/42985583-36fb-4e14-8642-bd837aac0727

?

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
}

发表评论
用户名: 匿名