开发者

Can I get a "__try"-clause to compile with /EHsc?

开发者 https://www.devze.com 2023-02-14 09:51 出处:网络
The Microsoft-approved way of setting a thread name doesn\'t compile with /EHsc enabled. The compiler tells me

The Microsoft-approved way of setting a thread name doesn't compile with /EHsc enabled. The compiler tells me

C2712: Cannot use __try in functions that require object unwinding

http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx

//
// Usage: SetThreadName (-1, "MainThread");
//
typedef struct tagTHREADNAME_INFO
{
   DWORD dwType; // must be 0x1000
   LPCSTR szName; // pointer to name (in user addr space)
   DWORD dwThreadID; // thread ID (-1=caller thread)
   DWORD dwFlags; // reserved for future use, must be zero
} THREADNAME_INFO;

void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
{
   THREADNAME_INFO info;
   info.dwType = 0x1000;
   info.szName = szThreadName;
   info.dwThreadID = dwThreadID;
   info.dwFlags = 0;

   __try
   {
      RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );
   }
开发者_高级运维   __except(EXCEPTION_CONTINUE_EXECUTION)
   {
   }
}

Any idea on how to fix this without changing the compiler settings?

Using Visual Studio 2008 on WinXP


The usual solution is to separate it into two functions, one calling the other. One sets up the SEH __try/__except block and the other has all the stuff related to C++ exceptions and destructor calls for local variables.

But I don't see any types that need a destructor call.

Maybe it's just a typo (except) vs (__except)?

0

精彩评论

暂无评论...
验证码 换一张
取 消