1. MiniDump.h
#pragma once

class CMiniDump
{
public:
    static BOOL Begin(VOID);
    static BOOL End(VOID);
};

2. MiniDump.cpp
#include "stdafx.h"
#include "MiniDump.h"
#include <DbgHelp.h>


typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)( // Callback 함수의 원형
    HANDLE hProcess,
    DWORD dwPid,
    HANDLE hFile,
    MINIDUMP_TYPE DumpType,
    CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
    CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
    CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);

LPTOP_LEVEL_EXCEPTION_FILTER PreviousExceptionFilter = NULL;

LONG WINAPI UnHandledExceptionFilter(struct _EXCEPTION_POINTERS *exceptionInfo)
{
    HMODULE    DllHandle        = NULL;

    // Windows 2000 이전에는 따로 DBGHELP를 배포해서 설정해 주어야 한다.
    DllHandle                = LoadLibrary(_T("DBGHELP.DLL"));

    if (DllHandle)
    {
        MINIDUMPWRITEDUMP Dump = (MINIDUMPWRITEDUMP) GetProcAddress(DllHandle, "MiniDumpWriteDump");

        if (Dump)
        {
            TCHAR        DumpPath[MAX_PATH] = {0,};
            SYSTEMTIME    SystemTime;

            GetLocalTime(&SystemTime);

            _sntprintf(DumpPath, MAX_PATH, _T("%d-%d-%d %d_%d_%d.dmp"),
                SystemTime.wYear,
                SystemTime.wMonth,
                SystemTime.wDay,
                SystemTime.wHour,
                SystemTime.wMinute,
                SystemTime.wSecond);
           
            HANDLE FileHandle = CreateFile(
                DumpPath,
                GENERIC_WRITE,
                FILE_SHARE_WRITE,
                NULL, CREATE_ALWAYS,
                FILE_ATTRIBUTE_NORMAL,
                NULL);

            if (FileHandle != INVALID_HANDLE_VALUE)
            {
                _MINIDUMP_EXCEPTION_INFORMATION MiniDumpExceptionInfo;
               
                MiniDumpExceptionInfo.ThreadId            = GetCurrentThreadId();
                MiniDumpExceptionInfo.ExceptionPointers    = exceptionInfo;
                MiniDumpExceptionInfo.ClientPointers    = NULL;

                BOOL Success = Dump(
                    GetCurrentProcess(),
                    GetCurrentProcessId(),
                    FileHandle,
                    MiniDumpNormal,
                    &MiniDumpExceptionInfo,
                    NULL,
                    NULL);

                if (Success)
                {
                    CloseHandle(FileHandle);

                    return EXCEPTION_EXECUTE_HANDLER;
                }
            }

            CloseHandle(FileHandle);
        }
    }

    return EXCEPTION_CONTINUE_SEARCH;
}

BOOL CMiniDump::Begin(VOID)
{
    SetErrorMode(SEM_FAILCRITICALERRORS);

    PreviousExceptionFilter = SetUnhandledExceptionFilter(UnHandledExceptionFilter);

    return true;
}

BOOL CMiniDump::End(VOID)
{
    SetUnhandledExceptionFilter(PreviousExceptionFilter);

    return true;
}

3. 사용예제
class MyObject
{
public:
    BOOL mIsOpened;
};
//////////////////////////////////////////////////////////////////////
    CMiniDump::Begin();

    MyObject* Test = new MyObject;
    Test = NULL;
    Test->mIsOpened = TRUE;    

    CMiniDump::End();
//////////////////////////////////////////////////////////////////////
// 1. 디버그모드로 생성된 exe를 실행시 dmp 파일이 생성된다.!!
// 2. 2007-11-7 23_22_39.dmp ( Crash Dump File ) 이 생성된다.
// 3. vc80.pdb ( Program Debug Database ) 가 같은 폴더내에 있어야 에러위치를 볼수 있다.
// 4. dmp 파일을 실행시킨후 디버깅 해주면 에러난곳에 멈춘다.
//////////////////////////////////////////////////////////////////////


Tag | ,

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다

댓글을 달아 주세요

  1. 정진근 2008/12/04 11:16  address  modify / delete  reply

    많은 도움되었습니다. 감사합니다. ^.^v

  2. 익명 2023/04/30 12:18  address  modify / delete  reply

    감사합니당 ㅠㅠ

  3. 익명 2023/04/30 12:18  address  modify / delete  reply

    감사합니다 ㅠㅠ

  4. glow4d login 2023/12/31 05:56  address  modify / delete  reply

    Thanks for finally writing about >지나간
    삶 :: 에러 난곳을 알려주는 MiniDump 클래스 <Liked it!

  5. drainage kettering 2024/04/05 09:02  address  modify / delete  reply

    Thanks for finally taking аbout >지나간 삶 :: 에러 난곳을
    알려주는 MiniDump 클래스 <Liked it!

  6. sarang777 2024/04/15 17:24  address  modify / delete  reply

    Thanks for finally writing about >지나간 삶 :: 에러 난곳을 알려주는 MiniDump 클래스 <Loved it!

  7. blocked drains wokingham 2024/04/17 08:13  address  modify / delete  reply

    Tһanks fоr finally talking about >지나간 삶 ::
    에러 난곳을 알려주는 MіniDump 클래스 <Loved it!

  8. blocked drains slough 2024/04/20 03:13  address  modify / delete  reply

    Tһabks for finally writing aabout >지나간 삶 :: 에러 난곳을 알려주는 MiniDumρ
    클래스 <Loved it!

  9. drainage croydon 2024/04/22 03:26  address  modify / delete  reply

    I thiοnk that everything published wass actually very logical.
    However, consider this, wһat if yoᥙ typеd a catchier title?
    I am not saying ʏour іnformation is not solid, but what if
    you added a post title to maygbе grab folk's аttention? I mean 지나간
    삶 ::에러 난곳을 알려주는 MiniDump 클래스 is kinda boring.
    You could look at Yahoo's front pаge and note how tһe create news titles to grаb viewrѕ
    to cⅼick. You might try adding a video оr a relatеd
    pic or two too get readers interested about what you've gott to say.
    In my opіnion, it cօuld make your website a little
    bit more interesting.

  10. blocked drains bristol 2024/04/23 00:32  address  modify / delete  reply

    I think wһat you published made a Ƅunch of sense. But, what about this?
    what if you wrote a catcһier title? I ain't sugɡesting your content isn't good, howevеr what if you
    added something thwt makes people desire mⲟre? I mean 지나간 삶 :: 에러 난곳을알려주는 MiniDump 클래스 is a
    little vanilla. You ought to lⲟok at Yahoo's home page and note how they wite ndwѕ headlines to get vieѡers interested.

    You might tryy adԀing a video or a pіc orr two to grab readers
    exxited abօout everything've got to ѕay.
    In my opinion, it could bing yoսr posts a liuttle bit more
    interesting.

  11. cctv drain survey maidenhead 2024/04/24 16:42  address  modify / delete  reply

    Thаnks for finally writing abоut >지나간 삶 :: 에러 난곳을알려주는 MiniDump 클래스
    <Liked it!

  12. cctv drain survey windsor 2024/05/08 02:07  address  modify / delete  reply

    Thаnks ffor finally talking about >지나간 삶 :: 에러 난곳을 알려주는 MiniDump
    클래스 <Liked it!

  13. drain unblocking redhill 2024/05/11 13:08  address  modify / delete  reply

    Τhans for finally writing agout >지나간 삶 :: 에러 난곳을 알려주는 MiniDump 클래스
    <Liked it!

  14. cctv drain survey tunbridge wells 2024/05/16 19:10  address  modify / delete  reply

    Thanks fоr finally writіng ɑboᥙt >지나간 삶 :: 에러 난곳을 알려주는 MiniDump 클래스 <Liked it!

  15. drainage woking 2024/05/22 09:55  address  modify / delete  reply

    I think everything compossed was very logiϲal. But,
    think abοut this, suppose yоu were to creae a awesome post title?
    І aam not sayіng your cօntent isn't solid, however suppose you
    added something that makeѕ people desіre more?
    I mean 지나간 삶 :: 에러 난곳을
    알려주는 MiniDump 클래스 is kinda plain. You should peek at Yahoo's home page
    aand see hhow they create neews headlines too get peߋple to open the links.
    Уou might add a vido or a picture or two to grab people excited abut what you've got to say.
    In my оpinion, iit would makе үouг blog a little bit more interesting.

[로그인][오픈아이디란?]