1
0

threadname.h 768 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef NULLSOFT_UTILITY_THREADNAME_H
  2. #define NULLSOFT_UTILITY_THREADNAME_H
  3. #ifdef _DEBUG
  4. #include <windows.h>
  5. typedef struct tagTHREADNAME_INFO
  6. {
  7. DWORD dwType; // must be 0x1000
  8. LPCSTR szName; // pointer to name (in user addr space)
  9. DWORD dwThreadID; // thread ID (-1=caller thread)
  10. DWORD dwFlags; // reserved for future use, must be zero
  11. }
  12. THREADNAME_INFO;
  13. __inline void SetThreadName(DWORD dwThreadID, const char *szThreadName)
  14. {
  15. THREADNAME_INFO info;
  16. info.dwType = 0x1000;
  17. info.szName = szThreadName;
  18. info.dwThreadID = dwThreadID;
  19. info.dwFlags = 0;
  20. __try
  21. {
  22. RaiseException( 0x406D1388, 0, sizeof(info) / sizeof(DWORD), (const ULONG_PTR *)&info );
  23. }
  24. __except(EXCEPTION_CONTINUE_EXECUTION)
  25. {}
  26. }
  27. #else
  28. #define SetThreadName(x,y)
  29. #endif
  30. #endif