Windows 生成dump文件
#ifdef _WIN32
#include <Windows.h>
#include <Dbghelp.h>
#pragma comment(lib, "Dbghelp.lib")
LONG WINAPI CrashHandlerExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers)
{
char settingdir[MAX_PATH * 2 + 1];
char s_szExceptionDumpFileName[MAX_PATH * 2 + 1];
memset(settingdir, 0, sizeof(settingdir));
memset(s_szExceptionDumpFileName, 0, sizeof(s_szExceptionDumpFileName));
char * appData = getenv("appdata");
memcpy(settingdir, appData, strlen(appData) + 1);
SYSTEMTIME st;
GetLocalTime(&st);
strcat(settingdir, "\\\\");
strcat(settingdir, "CloudGaming");
strcat(settingdir, "\\\\crash");
CreateDirectoryA(settingdir, NULL);
sprintf(s_szExceptionDumpFileName, "%s\\\\manager_%02d%02d%02d%02d%02d%02d.dmp", settingdir, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
HANDLE hDumpFile = ::CreateFileA(s_szExceptionDumpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hDumpFile) {
MINIDUMP_EXCEPTION_INFORMATION einfo;
einfo.ThreadId = ::GetCurrentThreadId();
einfo.ExceptionPointers = pExceptionPointers;
einfo.ClientPointers = FALSE;
::MiniDumpWriteDump(::GetCurrentProcess(),
::GetCurrentProcessId(),
hDumpFile,
MiniDumpNormal,
&einfo,
NULL,
NULL);
CloseHandle(hDumpFile);
}
return EXCEPTION_EXECUTE_HANDLER;
}
#endif
int main(int argc, char *argv[])
{
#ifdef _WIN32
SetUnhandledExceptionFilter(CrashHandlerExceptionFilter);
#endif
}