MiniDump.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <dbghelp.h>
  4. #pragma comment(lib, "Dbghelp.lib")
  5. #define DUMP_TYPE MiniDumpNormal| MiniDumpWithDataSegs | MiniDumpWithCodeSegs | MiniDumpWithFullMemory\
  6. | MiniDumpWithThreadInfo | MiniDumpWithPrivateReadWriteMemory\
  7. LONG WINAPI _UnhandledExceptionFilter( struct _EXCEPTION_POINTERS *lpExceptionInfo )
  8. {
  9. LONG ret = EXCEPTION_EXECUTE_HANDLER;
  10. TCHAR szFileName[64];
  11. SYSTEMTIME st;
  12. ::GetLocalTime(&st);
  13. wsprintf(szFileName, TEXT("¡¾%04d-%02d-%02d-%02d-%02d-%02d-%02d-%02d¡¿_OCC_V3.0.dmp"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, rand()%100);
  14. HANDLE hFile = ::CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  15. if ( hFile != INVALID_HANDLE_VALUE )
  16. {
  17. MINIDUMP_EXCEPTION_INFORMATION ExInfo;
  18. ExInfo.ThreadId = ::GetCurrentThreadId();
  19. ExInfo.ExceptionPointers = lpExceptionInfo;
  20. ExInfo.ClientPointers = false;
  21. // write the dump
  22. BOOL bOK = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithFullMemory, &ExInfo, NULL, NULL );
  23. if ( bOK )
  24. {
  25. printf("Create Dump File Success!/n");
  26. }
  27. else
  28. {
  29. printf("MiniDumpWriteDump Failed: %d/n", GetLastError());
  30. }
  31. ::CloseHandle(hFile);
  32. }
  33. else
  34. {
  35. printf("Create File %s Failed %d/n", szFileName, GetLastError());
  36. }
  37. return ret;
  38. }