Merge branch 'restructure-tree'
[TortoiseGit.git] / src / Utils / DebugHelpers.cpp
blobf550450f3ab97b76385447be644c8dcc7a97d2eb
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006 - Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "StdAfx.h"
20 #include "debughelpers.h"
22 CString GetLastErrorMessageString(int err)
24 LPVOID lpMsgBuf;
25 FormatMessage(
26 FORMAT_MESSAGE_ALLOCATE_BUFFER |
27 FORMAT_MESSAGE_FROM_SYSTEM |
28 FORMAT_MESSAGE_IGNORE_INSERTS,
29 NULL,
30 err,
31 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
32 (LPTSTR) &lpMsgBuf,
34 NULL
36 CString temp = CString((LPCTSTR)lpMsgBuf);
37 LocalFree(lpMsgBuf);
38 return temp;
41 CString GetLastErrorMessageString()
43 LPVOID lpMsgBuf;
44 FormatMessage(
45 FORMAT_MESSAGE_ALLOCATE_BUFFER |
46 FORMAT_MESSAGE_FROM_SYSTEM |
47 FORMAT_MESSAGE_IGNORE_INSERTS,
48 NULL,
49 GetLastError(),
50 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
51 (LPTSTR) &lpMsgBuf,
53 NULL
55 CString temp = CString((LPCTSTR)lpMsgBuf);
56 LocalFree(lpMsgBuf);
57 return temp;
60 void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName)
62 #ifdef _UNICODE
63 char narrow[_MAX_PATH * 3];
64 BOOL defaultCharUsed;
65 int ret = WideCharToMultiByte(CP_ACP, 0, szThreadName, (int)_tcslen(szThreadName), narrow, _MAX_PATH*3 - 1, ".", &defaultCharUsed);
66 narrow[ret] = 0;
67 #endif
68 THREADNAME_INFO info;
69 info.dwType = 0x1000;
70 #ifdef _UNICODE
71 info.szName = narrow;
72 #else
73 info.szName = szThreadName;
74 #endif
75 info.dwThreadID = dwThreadID;
76 info.dwFlags = 0;
78 __try
80 RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD),
81 (const ULONG_PTR *)&info);
83 __except (EXCEPTION_CONTINUE_EXECUTION)