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