#ifndef __FC_DUMP_H__ #define __FC_DUMP_H__ #include #include #include #pragma comment( lib, "DbgHelp.lib" ) class _FCDump { protected: static LONG WINAPI _fcUnhandledExceptionFilter( _In_ struct _EXCEPTION_POINTERS *ExceptionInfo ) { TCHAR appPath[MAX_PATH] = { 0 }; GetModuleFileName(NULL, appPath, MAX_PATH); TCHAR* lastslot = _tcsrchr(appPath, '.'); if (lastslot) *lastslot = 0; time_t tNow = time(NULL); struct tm tmNow; localtime_s(&tmNow, &tNow); TCHAR sTime[MAX_PATH] = { 0 }; swprintf_s(sTime, L"%s.dmp" , appPath); HANDLE lhDumpFile = CreateFile(sTime, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); MINIDUMP_EXCEPTION_INFORMATION loExceptionInfo; loExceptionInfo.ExceptionPointers = ExceptionInfo; loExceptionInfo.ThreadId = GetCurrentThreadId(); loExceptionInfo.ClientPointers = TRUE; MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),lhDumpFile, MiniDumpNormal, &loExceptionInfo, NULL, NULL); CloseHandle(lhDumpFile); return EXCEPTION_EXECUTE_HANDLER; } static void _fcInvalidParameterHandler( const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved ) { char appPath[ MAX_PATH ] = {0}; GetModuleFileNameA( NULL, appPath, MAX_PATH ); char* lastslot = strrchr( appPath, '.' ); if( lastslot ) *lastslot = 0; time_t tNow = time(NULL); struct tm tmNow; localtime_s( &tmNow, &tNow ); char sDumpPath[ MAX_PATH ] = {0}; sprintf_s( sDumpPath, "%s.iph" , appPath ); HANDLE lhDumpFile = CreateFileA(sDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); USES_CONVERSION; char buffer[1024]; DWORD nLen = 0; sprintf_s( buffer, "传入函数<%s>的参数无效.\nFile: %s Line: %d\n", W2A(function), W2A(file), line ); WriteFile( lhDumpFile, buffer, strlen( buffer ), &nLen, NULL ); sprintf_s( buffer, "异常描述: %s\n", W2A(expression) ); WriteFile( lhDumpFile, buffer, strlen( buffer ), &nLen, NULL ); CloseHandle(lhDumpFile); throw(1); } static void _fcPurecallHandler(void) { throw(1); } public: static void StartDump( void ) { SetUnhandledExceptionFilter( &_fcUnhandledExceptionFilter ); _set_invalid_parameter_handler( _fcInvalidParameterHandler ); _set_purecall_handler( _fcPurecallHandler ); _CrtSetReportMode( _CRT_ASSERT, 0 ); } }; #endif // !__FC_DUMP_H__