altdef.h 都是这个文件里的定义#ifndef ATLTRY
#define ATLTRY(x) ATLTRYALLOC(x)
#endif //ATLTRY出问题的都是这个宏
ATLTRY(szKey = new TCHAR[cbKey];)
ATLTRY(pszW.Allocate(_convert));
                  ATLTRY(szReg.Allocate(dwSize + 1));
1>FilterImageGrabber.cpp
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(954) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(954) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(970) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(970) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(995) : error C2712: 无法在要求对象展开的函数中使用 __try
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1008) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1008) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1024) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1024) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1190) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlcomcli.h(1190) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(107) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(107) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(113) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(113) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(423) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(423) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(587) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(587) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(901) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(901) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(971) : error C2059: 语法错误 : “catch”
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\statreg.h(971) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)

解决方案 »

  1.   

    第一句:ATLTRY(szKey = new TCHAR[cbKey];)冒号在刮号前面
      

  2.   

    只有 try 没有 catch ?
      

  3.   

    msdn里有地方说这个宏不是这么定义的
    真奇怪。
      

  4.   

    http://msdn.microsoft.com/en-us/library/ms972340.aspxExceptions
    C++ exceptions are turned off for ATL components, by default, to reduce the size of the components, as the C Runtime Library is required if exceptions are enabled. This has a few implications, notably that new does not throw exceptions, as it normally would. Instead it returns NULL. C++ exception handling can be turned on, however, and it will be if MFC is also being used. Accordingly, the ATL source is sprinkled with code like this:Copy Code 
        CFoo* pFoo = NULL;
        ATLTRY(pFoo = new CFoo(_T("Hello"), 7))
        if (pFoo == NULL)
            return E_OUTOFMEMORY;where ATLTRY is defined as:Copy Code 
    #if defined (_CPPUNWIND) & \
        (defined(_ATL_EXCEPTIONS) | defined(_AFX))
    # define ATLTRY(x) try{x;} catch(...) {}
    #else
    # define ATLTRY(x) x;
    #endifIt's up to you to decide if you want to turn on exceptions. Making a component 25K larger by linking in the C Runtime Library is much less of an issue for server components than for downloadable browser components, and you probably want other features of the CRT anyway. If you do turn on exceptions, be aware that it is considered extremely bad form to throw C++ exceptions or SEH exceptions across COM boundaries, so you should catch all exceptions thrown in your code. If you leave exceptions disabled, then you must check for NULL.我把c++异常关闭了也不起作用。
      

  5.   

    http://topic.csdn.net/u/20071017/15/8c2a8d0f-159f-4afd-ba1c-554cf0f7d493.html问题已经解决,原来是工程属性-〉预定义里的问题,它在里面定义了try=_try,把这个删除就OK了,找的好辛苦, 
    分数就送给唯一的一位热心人了。——————————————————————————————————————————————————————————————
    这个定义在那里 我怎么没找啊。try=_try
      

  6.   


    #ifndef ATLTRYALLOC
    #define ATLTRYALLOC(x) x;
    #endif //ATLTRYALLOC// if _ATLTRY is defined before including this file then 
    // _ATLCATCH and _ATLRETHROW should be defined as well.
    #ifndef _ATLTRY
    #define _ATLTRY
    #define _ATLCATCH( e ) __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop))
    #define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop))
    #define _ATLDELETEEXCEPTION(e)
    #define _ATLRETHROW
    #endif // _ATLTRY#endif //_CPPUNWIND#ifndef ATLTRY
    #define ATLTRY(x) ATLTRYALLOC(x)
    #endif //ATLTRY#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)
      

  7.   


    ATLTRY(szKey = new TCHAR[cbKey]);try
    {
    }
    catch(...)
    {
    }
      

  8.   

    http://zhanyonhu.blog.163.com/blog/static/16186044200941405453403/这里提到一个解决方法,但是我看不太明白 。现在ATLTRYALLOC的定义是#define ATLTRYALLOC(x) x;,这个不对。  在项目属性的预编译头中加入_CPPUNWIND,这时,ATLTRYALLOC的定义是#define ATLTRYALLOC(x) __pragma(warning(push)) __pragma(warning(disable: 4571)) try{x;} catch(...) {} 在项目属性的预编译头中加入_CPPUNWIND
    这个东西怎么添加
      

  9.   

    项目属性 | 配置属性 | C/C++ | 预处理器 | 预处理器定义 
    然后在右边 加入 _CPPUNWIND