Here is the code I'm using.
This is the header file.
#pragma once #define MS_VC_EXCEPTION 0x406d1388 #pragma warning(disable: 6312) #pragma warning(disable: 6322) typedef struct tagTHREADNAME_INFO { DWORD dwType; // must be 0x1000 LPCSTR szName; // pointer to name (in same addr space) DWORD dwThreadID; // thread ID (-1 caller thread) DWORD dwFlags; // reserved for future use, most be zero } THREADNAME_INFO; inline void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) { #ifdef _DEBUG THREADNAME_INFO info; info.dwType = 0x1000; info.szName = szThreadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (DWORD *)&info); } __except (EXCEPTION_CONTINUE_EXECUTION) { } #else dwThreadID; szThreadName; #endif }
Then I call it like this in the proc stream.
SetThreadName(GetCurrentThreadId(), "VideoSource Thread");
It's worth noting that this is the exact code that David posted the link to (thanks! I forgot where I got it). I did not delete this message because I would like the code to still be available if MSDN decides to reorganize its links (again).
Jere.Jones Jan 26 '09 at 5:18 2009-01-26 05:18
source share