1 ///////////////////////////////////////////////////////////////////////////////
3 // Module: CrashRpt.cpp
5 // Desc: See CrashRpt.h
7 // Copyright (c) 2003 Michael Carruth
9 ///////////////////////////////////////////////////////////////////////////////
13 #include "CrashHandler.h"
15 #include "StackTrace.h"
18 #define CRASH_ASSERT(pObj) \
19 if (!pObj || sizeof(*pObj) != sizeof(CCrashHandler)) \
22 #define CRASH_ASSERT(pObj)
26 CRASHRPTAPI LPVOID
GetInstance()
28 CCrashHandler
*pImpl
= CCrashHandler::GetInstance();
33 CRASHRPTAPI LPVOID
InstallEx(LPGETLOGFILE pfn
, LPCTSTR lpcszTo
, LPCTSTR lpcszSubject
, BOOL bUseUI
)
36 OutputDebugString("InstallEx\n");
38 CCrashHandler
*pImpl
= CCrashHandler::GetInstance();
40 pImpl
->Install(pfn
, lpcszTo
, lpcszSubject
, bUseUI
);
45 CRASHRPTAPI
void UninstallEx(LPVOID lpState
)
47 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
53 CRASHRPTAPI
void EnableUIEx(LPVOID lpState
)
55 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
60 CRASHRPTAPI
void DisableUIEx(LPVOID lpState
)
62 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
67 CRASHRPTAPI
void EnableHandlerEx(LPVOID lpState
)
69 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
71 pImpl
->EnableHandler();
74 CRASHRPTAPI
void DisableHandlerEx(LPVOID lpState
)
76 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
78 pImpl
->DisableHandler();
81 CRASHRPTAPI
void AddFileEx(LPVOID lpState
, LPCTSTR lpFile
, LPCTSTR lpDesc
)
83 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
86 pImpl
->AddFile(lpFile
, lpDesc
);
89 CRASHRPTAPI
void RemoveFileEx(LPVOID lpState
, LPCTSTR lpFile
)
91 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
94 pImpl
->RemoveFile(lpFile
);
97 CRASHRPTAPI
void AddRegistryHiveEx(LPVOID lpState
, LPCTSTR lpHive
, LPCTSTR lpDesc
)
99 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
102 pImpl
->AddRegistryHive(lpHive
, lpDesc
);
105 CRASHRPTAPI
void RemoveRegistryHiveEx(LPVOID lpState
, LPCTSTR lpFile
)
107 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
110 pImpl
->RemoveRegistryHive(lpFile
);
114 CRASHRPTAPI
void AddEventLogEx(LPVOID lpState
, LPCTSTR lpHive
, LPCTSTR lpDesc
)
116 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
119 pImpl
->AddEventLog(lpHive
, lpDesc
);
122 CRASHRPTAPI
void RemoveEventLogEx(LPVOID lpState
, LPCTSTR lpFile
)
124 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
127 pImpl
->RemoveEventLog(lpFile
);
130 CRASHRPTAPI
void GenerateErrorReportEx(LPVOID lpState
, PEXCEPTION_POINTERS pExInfo
, BSTR message
)
132 CCrashHandler
*pImpl
= (CCrashHandler
*)lpState
;
135 if (!pImpl
->GenerateErrorReport(pExInfo
, message
)) {
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)
162 extern "C" void __stdcall
DisableUIVB()
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()
262 extern "C" void __stdcall
AddFileVB(LPCTSTR lpFile
, LPCTSTR lpDesc
)
264 AddFile(lpFile
, lpDesc
);
267 extern "C" void __stdcall
RemoveFileVB(LPCTSTR 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
);