This is Unofficial EPICS BASE Doxygen Site
setThreadName.cpp
Go to the documentation of this file.
1 
2 /*************************************************************************\
3 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
4 * National Laboratory.
5 * Copyright (c) 2002 The Regents of the University of California, as
6 * Operator of Los Alamos National Laboratory.
7 * EPICS BASE Versions 3.13.7
8 * and higher are distributed subject to a Software License Agreement found
9 * in file LICENSE that is included with this distribution.
10 \*************************************************************************/
11 
12 #define VC_EXTRALEAN
13 #define STRICT
14 #if _WIN64
15 # define _WIN32_WINNT 0x400 /* defining this drops support for W95 */
16 #endif
17 #include <windows.h>
18 
19 /*
20  * this was copied directly from an example in visual c++ 7 documentation,
21  * It uses visual C++ specific keywords for exception handling, but is
22  * probably only useful when using the visual c++ or later debugger.
23  *
24  * Usage: setThreadName (-1, "MainThread");
25  */
26 extern "C" void setThreadName ( DWORD dwThreadID, LPCSTR szThreadName )
27 {
28 #if _MSC_VER >= 1300 && defined ( _DEBUG )
29  typedef struct tagTHREADNAME_INFO
30  {
31  DWORD dwType; // must be 0x1000
32  LPCSTR szName; // pointer to name (in user addr space)
33  DWORD dwThreadID; // thread ID (-1=caller thread)
34  DWORD dwFlags; // reserved for future use, must be zero
35  } THREADNAME_INFO;
36  THREADNAME_INFO info;
37  info.dwType = 0x1000;
38  info.szName = szThreadName;
39  info.dwThreadID = dwThreadID;
40  info.dwFlags = 0;
41 
42  __try
43  {
44  RaiseException( 0x406D1388, 0,
45  sizeof(info)/sizeof(DWORD), (const ULONG_PTR*)&info );
46  }
47  __except(EXCEPTION_CONTINUE_EXECUTION)
48  {
49  }
50 #endif
51 }
void setThreadName(DWORD dwThreadID, LPCSTR szThreadName)