Make Scintilla use Direct2D on Vista and later
[TortoiseGit.git] / src / crashrpt / CrashRpt.cpp
blob044c5170f0f9d81802ef9f06d839b083fb7e1750
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Module: CrashRpt.cpp
4 //
5 // Desc: See CrashRpt.h
6 //
7 // Copyright (c) 2003 Michael Carruth
8 //
9 ///////////////////////////////////////////////////////////////////////////////
11 #include "stdafx.h"
12 #include "CrashRpt.h"
13 #include "CrashHandler.h"
15 #include "StackTrace.h"
17 #ifdef _DEBUG
18 #define CRASH_ASSERT(pObj) \
19 if (!pObj || sizeof(*pObj) != sizeof(CCrashHandler)) \
20 DebugBreak()
21 #else
22 #define CRASH_ASSERT(pObj)
23 #endif // _DEBUG
25 // New interfaces
26 CRASHRPTAPI LPVOID GetInstance()
28 CCrashHandler *pImpl = CCrashHandler::GetInstance();
29 CRASH_ASSERT(pImpl);
30 return pImpl;
33 CRASHRPTAPI LPVOID InstallEx(LPGETLOGFILE pfn, LPCTSTR lpcszTo, LPCTSTR lpcszSubject, BOOL bUseUI)
35 #ifdef _DEBUG
36 OutputDebugString("InstallEx\n");
37 #endif
38 CCrashHandler *pImpl = CCrashHandler::GetInstance();
39 CRASH_ASSERT(pImpl);
40 pImpl->Install(pfn, lpcszTo, lpcszSubject, bUseUI);
42 return pImpl;
45 CRASHRPTAPI void UninstallEx(LPVOID lpState)
47 CCrashHandler *pImpl = (CCrashHandler*)lpState;
48 CRASH_ASSERT(pImpl);
50 delete pImpl;
53 CRASHRPTAPI void EnableUIEx(LPVOID lpState)
55 CCrashHandler *pImpl = (CCrashHandler*)lpState;
56 CRASH_ASSERT(pImpl);
57 pImpl->EnableUI();
60 CRASHRPTAPI void DisableUIEx(LPVOID lpState)
62 CCrashHandler *pImpl = (CCrashHandler*)lpState;
63 CRASH_ASSERT(pImpl);
64 pImpl->DisableUI();
67 CRASHRPTAPI void EnableHandlerEx(LPVOID lpState)
69 CCrashHandler *pImpl = (CCrashHandler*)lpState;
70 CRASH_ASSERT(pImpl);
71 pImpl->EnableHandler();
74 CRASHRPTAPI void DisableHandlerEx(LPVOID lpState)
76 CCrashHandler *pImpl = (CCrashHandler*)lpState;
77 CRASH_ASSERT(pImpl);
78 pImpl->DisableHandler();
81 CRASHRPTAPI void AddFileEx(LPVOID lpState, LPCTSTR lpFile, LPCTSTR lpDesc)
83 CCrashHandler *pImpl = (CCrashHandler*)lpState;
84 CRASH_ASSERT(pImpl);
86 pImpl->AddFile(lpFile, lpDesc);
89 CRASHRPTAPI void RemoveFileEx(LPVOID lpState, LPCTSTR lpFile)
91 CCrashHandler *pImpl = (CCrashHandler*)lpState;
92 CRASH_ASSERT(pImpl);
94 pImpl->RemoveFile(lpFile);
97 CRASHRPTAPI void AddRegistryHiveEx(LPVOID lpState, LPCTSTR lpHive, LPCTSTR lpDesc)
99 CCrashHandler *pImpl = (CCrashHandler*)lpState;
100 CRASH_ASSERT(pImpl);
102 pImpl->AddRegistryHive(lpHive, lpDesc);
105 CRASHRPTAPI void RemoveRegistryHiveEx(LPVOID lpState, LPCTSTR lpFile)
107 CCrashHandler *pImpl = (CCrashHandler*)lpState;
108 CRASH_ASSERT(pImpl);
110 pImpl->RemoveRegistryHive(lpFile);
114 CRASHRPTAPI void AddEventLogEx(LPVOID lpState, LPCTSTR lpHive, LPCTSTR lpDesc)
116 CCrashHandler *pImpl = (CCrashHandler*)lpState;
117 CRASH_ASSERT(pImpl);
119 pImpl->AddEventLog(lpHive, lpDesc);
122 CRASHRPTAPI void RemoveEventLogEx(LPVOID lpState, LPCTSTR lpFile)
124 CCrashHandler *pImpl = (CCrashHandler*)lpState;
125 CRASH_ASSERT(pImpl);
127 pImpl->RemoveEventLog(lpFile);
130 CRASHRPTAPI void GenerateErrorReportEx(LPVOID lpState, PEXCEPTION_POINTERS pExInfo, BSTR message)
132 CCrashHandler *pImpl = (CCrashHandler*)lpState;
133 CRASH_ASSERT(pImpl);
135 if (!pImpl->GenerateErrorReport(pExInfo, message)) {
136 DebugBreak();
140 CRASHRPTAPI void StackTrace ( int numSkip, int depth, TraceCallbackFunction pFunction, CONTEXT *pContext, void *data)
142 DoStackTrace(numSkip, depth > 0 ? depth : 9999, pFunction, pContext, data);
145 // DLL Entry Points usable from Visual Basic
146 // explicit export is required to export undecorated names.
147 extern "C" LPVOID __stdcall InstallExVB(LPGETLOGFILE pfn, LPCTSTR lpcszTo, LPCTSTR lpcszSubject, BOOL bUseUI)
149 return InstallEx(pfn, lpcszTo, lpcszSubject, bUseUI);
152 extern "C" void __stdcall UninstallExVB(LPVOID lpState)
154 UninstallEx(lpState);
157 extern "C" void __stdcall EnableUIVB(void)
159 EnableUI();
162 extern "C" void __stdcall DisableUIVB()
164 DisableUI();
167 extern "C" void __stdcall AddFileExVB(LPVOID lpState, LPCTSTR lpFile, LPCTSTR lpDesc)
169 AddFileEx(lpState, lpFile, lpDesc);
172 extern "C" void __stdcall RemoveFileExVB(LPVOID lpState, LPCTSTR lpFile)
174 RemoveFileEx(lpState, lpFile);
177 extern "C" void __stdcall AddRegistryHiveExVB(LPVOID lpState, LPCTSTR lpRegistryHive, LPCTSTR lpDesc)
179 AddRegistryHiveEx(lpState, lpRegistryHive, lpDesc);
182 extern "C" void __stdcall RemoveRegistryHiveExVB(LPVOID lpState, LPCTSTR lpRegistryHive)
184 RemoveRegistryHiveEx(lpState, lpRegistryHive);
187 extern "C" void __stdcall GenerateErrorReportExVB(LPVOID lpState, PEXCEPTION_POINTERS pExInfo, BSTR message)
189 GenerateErrorReportEx(lpState, pExInfo, message);
192 extern "C" void __stdcall StackTraceVB(int numSkip, int depth, TraceCallbackFunction pFunction, CONTEXT *pContext, void *data)
194 StackTrace(numSkip, depth, pFunction, pContext, data);
197 // Compatibility interfaces
198 CRASHRPTAPI void Install(LPGETLOGFILE pfn, LPCTSTR lpcszTo, LPCTSTR lpcszSubject, BOOL bUseUI)
200 (void) InstallEx(pfn, lpcszTo, lpcszSubject, bUseUI);
203 CRASHRPTAPI void Uninstall()
205 UninstallEx(CCrashHandler::GetInstance());
208 CRASHRPTAPI void EnableUI()
210 EnableUIEx(CCrashHandler::GetInstance());
213 CRASHRPTAPI void DisableUI()
215 DisableUIEx(CCrashHandler::GetInstance());
218 CRASHRPTAPI void AddFile(LPCTSTR lpFile, LPCTSTR lpDesc)
220 AddFileEx(CCrashHandler::GetInstance(), lpFile, lpDesc);
223 CRASHRPTAPI void RemoveFile(LPCTSTR lpFile)
225 RemoveFileEx(CCrashHandler::GetInstance(), lpFile);
228 CRASHRPTAPI void AddRegistryHive(LPCTSTR lpRegistryHive, LPCTSTR lpDesc)
230 AddRegistryHiveEx(CCrashHandler::GetInstance(), lpRegistryHive, lpDesc);
233 CRASHRPTAPI void RemoveRegistryHive(LPCTSTR lpRegistryHive)
235 RemoveRegistryHiveEx(CCrashHandler::GetInstance(), lpRegistryHive);
237 CRASHRPTAPI void AddEventLog(LPCTSTR lpEventLog, LPCTSTR lpDesc)
239 AddEventLogEx(CCrashHandler::GetInstance(), lpEventLog, lpDesc);
242 CRASHRPTAPI void RemoveEventLog(LPCTSTR lpEventLog)
244 RemoveEventLogEx(CCrashHandler::GetInstance(), lpEventLog);
247 CRASHRPTAPI void GenerateErrorReport(BSTR message)
249 GenerateErrorReportEx(CCrashHandler::GetInstance(), NULL, message);
252 extern "C" void __stdcall InstallVB(LPGETLOGFILE pfn, LPCTSTR lpTo, LPCTSTR lpSubject, BOOL bUseUI)
254 Install(pfn, lpTo, lpSubject, bUseUI);
257 extern "C" void __stdcall UninstallVB()
259 Uninstall();
262 extern "C" void __stdcall AddFileVB(LPCTSTR lpFile, LPCTSTR lpDesc)
264 AddFile(lpFile, lpDesc);
267 extern "C" void __stdcall RemoveFileVB(LPCTSTR lpFile)
269 RemoveFile(lpFile);
272 extern "C" void __stdcall AddRegistryHiveVB(LPCTSTR lpRegistryHive, LPCTSTR lpDesc)
274 AddRegistryHive(lpRegistryHive, lpDesc);
277 extern "C" void __stdcall RemoveRegistryHiveVB(LPCTSTR lpRegistryHive)
279 RemoveRegistryHive(lpRegistryHive);
282 extern "C" void __stdcall AddEventLogVB(LPCTSTR lpEventLog, LPCTSTR lpDesc)
284 AddEventLog(lpEventLog, lpDesc);
287 extern "C" void __stdcall RemoveEventLogVB(LPCTSTR lpEventLog)
289 RemoveEventLog(lpEventLog);
292 extern "C" void __stdcall GenerateErrorReportVB(BSTR message)
294 GenerateErrorReport(message);