3 // Client crash callback
\r
4 typedef BOOL (CALLBACK *LPGETLOGFILE) (LPVOID lpvState);
\r
5 // Stack trace callback
\r
6 typedef void (*TraceCallbackFunction)(DWORD_PTR address, const char *ImageName,
\r
7 const char *FunctionName, DWORD functionDisp,
\r
8 const char *Filename, DWORD LineNumber, DWORD lineDisp,
\r
11 typedef LPVOID (*InstallEx)(LPGETLOGFILE pfn, LPCSTR lpcszTo, LPCSTR lpcszSubject, BOOL bUseUI);
\r
12 typedef void (*UninstallEx)(LPVOID lpState);
\r
13 typedef void (*EnableUI)(void);
\r
14 typedef void (*DisableUI)(void);
\r
15 typedef void (*EnableHandler)(void);
\r
16 typedef void (*DisableHandler)(void);
\r
17 typedef void (*AddFileEx)(LPVOID lpState, LPCSTR lpFile, LPCSTR lpDesc);
\r
18 typedef void (*AddRegistryEx)(LPVOID lpState, LPCSTR lpRegistry, LPCSTR lpDesc);
\r
19 typedef void (*AddEventLogEx)(LPVOID lpState, LPCSTR lpEventLog, LPCSTR lpDesc);
\r
23 * This class wraps the most important functions the CrashRpt-library
\r
24 * offers. To learn more about the CrashRpt-library go to
\r
25 * http://www.codeproject.com/debug/crash_report.asp \n
\r
26 * To compile the library you need the WTL. You can get the WTL
\r
27 * directly from Microsoft:
\r
28 * http://www.microsoft.com/downloads/details.aspx?FamilyID=128e26ee-2112-4cf7-b28e-7727d9a1f288&DisplayLang=en \n
\r
30 * Many changes were made to the library so if you read the
\r
31 * article on CodeProject also read the change log in the source
\r
33 * The most important changes are:
\r
34 * - stack trace is included in the report, with symbols/linenumbers if available
\r
35 * - "save" button so the user can save the report instead of directly send it
\r
36 * - can be used by multiple applications
\r
37 * - zlib linked statically, so no need to ship the zlib.dll separately
\r
39 * To use the library just include the header file "CrashReport.h"
\r
41 * #include "CrashReport.h"
\r
43 * Then you can either declare an instance of the class CCrashReport
\r
44 * somewhere globally in your application like this:
\r
46 * CCrashReport g_crasher("report@mycompany.com", "Crash report for MyApplication");
\r
48 * that way you can't add registry keys or additional files to the report, but
\r
49 * it's the fastest and easiest way to use the library.
\r
50 * Another way is to declare a global variable and initialize it in e.g. InitInstance()
\r
52 * CCrashReport g_crasher;
\r
53 * //then somewhere in InitInstance.
\r
54 * g_crasher.AddFile("mylogfile.log", "this is a log file");
\r
55 * g_crasher.AddRegistry("HKCU\\Software\\MyCompany\\MyProgram");
\r
59 * \remark the dll is dynamically linked at runtime. So the main application
\r
60 * will still work even if the dll is not shipped.
\r
67 * Construct the CrashReport-Object. This loads the dll
\r
68 * and initializes it.
\r
69 * \param lpTo the mail address the crash report should be sent to
\r
70 * \param lpSubject the mail subject
\r
72 CCrashReport(LPCSTR lpTo = NULL, LPCSTR lpSubject = NULL, BOOL bUseUI = TRUE)
\r
74 InstallEx pfnInstallEx;
\r
75 TCHAR szFileName[_MAX_PATH];
\r
76 GetModuleFileName(NULL, szFileName, _MAX_FNAME);
\r
78 // C:\Programme\TortoiseSVN\bin\TortoiseProc.exe -> C:\Programme\TortoiseSVN\bin\CrashRpt.dll
\r
79 CString strFilename = szFileName;
\r
80 strFilename = strFilename.Left(strFilename.ReverseFind(_T('\\')) + 1);
\r
81 strFilename += _T("CrashRpt.dll");
\r
83 m_hDll = LoadLibrary(strFilename);
\r
86 pfnInstallEx = (InstallEx)GetProcAddress(m_hDll, "InstallEx");
\r
89 m_lpvState = pfnInstallEx(NULL, lpTo, lpSubject, bUseUI);
\r
95 UninstallEx pfnUninstallEx;
\r
96 if ((m_hDll)&&(m_lpvState))
\r
98 pfnUninstallEx = (UninstallEx)GetProcAddress(m_hDll, "UninstallEx");
\r
99 pfnUninstallEx(m_lpvState);
\r
101 FreeLibrary(m_hDll);
\r
104 * Adds a file which will be included in the crash report. Use this
\r
105 * if your application generates log-files or the like.
\r
106 * \param lpFile the full path to the file
\r
107 * \param lpDesc a description of the file, used in the crash report dialog
\r
109 void AddFile(LPCSTR lpFile, LPCSTR lpDesc)
\r
111 AddFileEx pfnAddFileEx;
\r
112 if ((m_hDll)&&(m_lpvState))
\r
114 pfnAddFileEx = (AddFileEx)GetProcAddress(m_hDll, "AddFileEx");
\r
115 (pfnAddFileEx)(m_lpvState, lpFile, lpDesc);
\r
119 * Adds a whole registry tree to the crash report.
\r
120 * \param lpFile the full registry path, e.g. "HKLM\\Software\\MyApplication"
\r
121 * \param lpDesc a description of the generated registry file, used in the crash report dialog
\r
123 void AddRegistry(LPCSTR lpFile, LPCSTR lpDesc)
\r
125 AddRegistryEx pfnAddRegistryEx;
\r
126 if ((m_hDll)&&(m_lpvState))
\r
128 pfnAddRegistryEx = (AddRegistryEx)GetProcAddress(m_hDll, "AddRegistryHiveEx");
\r
129 (pfnAddRegistryEx)(m_lpvState, lpFile, lpDesc);
\r
133 * Adds a system Event Log to the crash report.
\r
137 void AddEventLog(LPCSTR lpFile, LPCSTR lpDesc)
\r
139 AddEventLogEx pfnAddEventLogEx;
\r
140 if ((m_hDll)&&(m_lpvState))
\r
142 pfnAddEventLogEx = (AddEventLogEx)GetProcAddress(m_hDll, "AddEventLogEx");
\r
143 (pfnAddEventLogEx)(m_lpvState, lpFile, lpDesc);
\r
148 void Enable(BOOL bEnable)
\r
150 EnableHandler pfnEnableHandler;
\r
151 DisableHandler pfnDisableHandler;
\r
152 if ((m_hDll)&&(m_lpvState))
\r
156 pfnEnableHandler = (EnableHandler)GetProcAddress(m_hDll, "EnableHandlerEx");
\r
157 (pfnEnableHandler)();
\r
161 OutputDebugString(_T("Calling DisableHandlerEx\n"));
\r
163 pfnDisableHandler = (DisableHandler)GetProcAddress(m_hDll, "DisableHandlerEx");
\r
164 (pfnDisableHandler)();
\r