#include "StdAfx.h"
#include <Shlwapi.h>
#include "CrashRpt.h"
#include "CrashRptSupport.h"
#pragma comment(lib, "Shlwapi")
#define LINK_WITH_CRASH_SUPPORT
#ifdef LINK_WITH_CRASH_SUPPORT
#pragma comment(lib, "CrashRpt/CrashRpt1402.lib")
#pragma message("Auto-Linking with CrashRpt1402.lib for support crash report ...")
#endif
int CCrashRptSupport::m_nInstallStatus = 0;
static CString GetModulePath( HMODULE hModule )
{
TCHAR szPath[MAX_PATH];
::GetModuleFileName(hModule, szPath, MAX_PATH);
::PathRemoveFileSpec(szPath);
::PathAddBackslash(szPath);
return szPath;
}
void CCrashRptSupport::InstallCrashRpt()
{
#ifdef LINK_WITH_CRASH_SUPPORT
CR_INSTALL_INFO info = {
0
};
// 设置结构体大小
info.cb = sizeof(info);
// Install all available exception handlers
info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS;
info.dwFlags |= CR_INST_CRT_EXCEPTION_HANDLERS;
// Installs exception handlers for newly created threads automatically.
info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS;
// 保存为本地压缩包
info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;
// 将未发送的错误报告放在EXE所在的目录ErrorReports下
const CString reportSaveDir = GetModulePath(NULL) + _T("ErrorReports");
info.pszErrorReportSaveDir = static_cast <LPCTSTR>(reportSaveDir);
// Disable sending error report over HTTP
info.uPriorities[CR_HTTP] = CR_NEGATIVE_PRIORITY;
// Disable sending error report over SMTP
info.uPriorities[CR_SMTP] = CR_NEGATIVE_PRIORITY;
// Disable sending error report over system email program
info.uPriorities[CR_SMAPI] = CR_NEGATIVE_PRIORITY;
// 设置MiniDump包含的数据类型
info.uMiniDumpType = static_cast <MINIDUMP_TYPE>(MiniDumpNormal |
MiniDumpWithDataSegs |
MiniDumpWithHandleData |
MiniDumpWithUnloadedModules |
MiniDumpWithProcessThreadData |
MiniDumpWithThreadInfo |
MiniDumpWithIndirectlyReferencedMemory |
MiniDumpWithPrivateReadWriteMemory |
MiniDumpWithFullMemoryInfo);
// Install crash reporting
m_nInstallStatus = crInstall(&info);
// Check that installed OK
if (m_nInstallStatus != 0)
{
TCHAR szErrorMsg[256];
crGetLastErrorMsg(szErrorMsg, 256);
AfxMessageBox(CString(_T("Install CrashRpt fail:\r\n")) + szErrorMsg, MB_ICONERROR);
}
// Add screen shot support
crAddScreenshot2(CR_AS_PROCESS_WINDOWS | CR_AS_USE_JPEG_FORMAT, 60);
#endif
}
void CCrashRptSupport::UninstallCrashRpt()
{
#ifdef LINK_WITH_CRASH_SUPPORT
if (m_nInstallStatus == 0)
{
// Uninstall crash reporting if installed
crUninstall();
m_nInstallStatus = 0;
}
#endif
}
评论0