zoukankan      html  css  js  c++  java
  • VS2008 dump

     1 #include <DbgHelp.h>
     2 #include <stdlib.h>
     3 #pragma comment(lib, "dbghelp.lib")
     4 
     5 BOOL IsDataSectionNeeded(const WCHAR* pModuleName)
     6 {
     7     if(pModuleName == 0)
     8     {
     9         return FALSE;
    10     }
    11 
    12     WCHAR szFileName[_MAX_FNAME] = L"";
    13     _wsplitpath(pModuleName, NULL, NULL, szFileName, NULL);
    14     if(wcsicmp(szFileName, L"ntdll") == 0)
    15         return TRUE;
    16 
    17     return FALSE;
    18 }
    19 
    20 BOOL CALLBACK MiniDumpCallback(PVOID
    21                                pParam,const PMINIDUMP_CALLBACK_INPUT   pInput,
    22                                PMINIDUMP_CALLBACK_OUTPUT        pOutput)
    23 {
    24     if(pInput == 0 || pOutput == 0)
    25         return FALSE;
    26 
    27     switch(pInput->CallbackType)
    28     {
    29     case ModuleCallback:
    30         if(pOutput->ModuleWriteFlags & ModuleWriteDataSeg)
    31             if(!IsDataSectionNeeded(pInput->Module.FullPath))
    32                 pOutput->ModuleWriteFlags &= (~ModuleWriteDataSeg);
    33     case IncludeModuleCallback:
    34     case IncludeThreadCallback:
    35     case ThreadCallback:
    36     case ThreadExCallback:
    37         return TRUE;
    38     default:;
    39     }
    40 
    41     return FALSE;
    42 }
    43 
    44 LONG __stdcall AppUnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo)
    45 {
    46     // create dump file
    50     TCHAR szPath[MAX_PATH] = {0};
    51     ::GetModuleFileName(NULL, szPath, MAX_PATH);
    52     CString strPath(szPath);
    53     strPath = strPath.Mid(0, strPath.ReverseFind(_T('\'))+1);
    54     strPath += _T("myApp.dmp");
    55 
    56     HANDLE hFile = CreateFile(strPath, GENERIC_READ | GENERIC_WRITE,
    57         FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    58 
    59     if((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
    60     {
    61         MINIDUMP_EXCEPTION_INFORMATION mdei;
    62         mdei.ThreadId           = GetCurrentThreadId();
    63         mdei.ExceptionPointers  = pExceptionInfo;
    64         mdei.ClientPointers     = NULL;
    65 
    66         MINIDUMP_CALLBACK_INFORMATION mci;
    67         mci.CallbackRoutine     = (MINIDUMP_CALLBACK_ROUTINE)MiniDumpCallback;
    68         mci.CallbackParam       = 0;
    69 
    70         ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), hFile, MiniDumpNormal, (pExceptionInfo != 0) ? &mdei : 0, NULL, &mci);
    71         CloseHandle(hFile);
    72     }
    73 
    74     return EXCEPTION_EXECUTE_HANDLER;
    75 }
    76 
    77 void StartUnhandledExceptionFilter()
    78 {
    79     ::SetUnhandledExceptionFilter(AppUnhandledExceptionFilter);
    80 }
  • 相关阅读:
    如何将平时所学的代码知识,用在实际测试场景中
    CSS,XTHML书写规范以及常见问题总结
    网页底部定位
    时不我待
    用CSS设置Table的细边框的最好用的方法
    CSS Hack总结说明
    批处理轻松删除Win7下WINDOWS.OLD文件夹
    通过iframe调用页面的一部分,实现自己想要的页面
    超简单的javascript
    form在IE6中会影响样式的问题
  • 原文地址:https://www.cnblogs.com/mymeng_feng/p/4287661.html
Copyright © 2011-2022 走看看