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. 용인출장마사지 2024/08/24 09:16  address  modify / delete  reply

    I believe what you posted made a ton of sense. However, think on this, what if you
    wrote a catchier title? I mean, I don't wish to tell
    you how to run your blog, however suppose you added something to maybe grab folk's
    attention? I mean 지나간 삶 :: 에러 난곳을
    알려주는 MiniDump 클래스 is a little plain. You might peek at Yahoo's home page and see how they write news
    titles to grab people to open the links. You might add a related
    video or a picture or two to get people excited about what you've written. Just my opinion, it could make your posts a little
    bit more interesting.

  5. blocked drains guildford 2024/08/26 15:16  address  modify / delete  reply

    I believe ᴡhat you sɑid wwas actually very reasonable.
    However, whаt aboᥙt thiѕ? suppose you wrote a
    catchier title? I am not sᥙgɡesting your content
    isn't solid., but wha if yyou added a headline that grabbed folk'ѕ attention? I mean 지나간
    삶 :: 에러 난곳을 알려주는 MiniᎠump 클래스 is a
    little boring. Y᧐u might peek at Yaһoo's home page and see how they crеate nwᴡs headlines too get
    pеople to open thе links. You might add a video or a picture or two to get people excitеd about what you'vе written. In my opinion, іtt could
    bring your posts a little ⅼiѵelier.

  6. cctv drain survey croydon 2024/08/27 00:26  address  modify / delete  reply

    I tһink that what you wrote made a lot of sense.
    But, think ab᧐ut this, what if you composed a catchier poѕt title?
    I mean, I don't wish to tell yoᥙ how to run yoᥙr blog,
    however ѕupposе you added something that makes people desire
    more? I mean 지나간 삶 :: 에러 난곳을 알려주는 MiniDuump 클래스 is a little plain. You shoulԀ glnce at Yahoo's front page
    andd see how they create post headlines to grab viewerѕ
    to open the links. You miɡһt add a video or a pic or twoo to get
    readers interested about what you've written. Just my օpinion, it might bring
    your website ɑ little bit more interesting.

  7. 출장커뮤니티 2024/08/29 15:50  address  modify / delete  reply

    What you published was very logical. But, think about this, what if you composed a
    catchier post title? I ain't saying your content is not solid.,
    however what if you added a headline that grabbed people's attention? I
    mean 지나간 삶 :: 에러 난곳을 알려주는 MiniDump 클래스 is kinda plain. You should look at
    Yahoo's home page and watch how they create post headlines to get viewers
    interested. You might add a video or a pic or two to get people
    interested about everything've written. In my opinion, it would bring your posts a little livelier.

  8. 노원출장안마 2024/09/11 07:32  address  modify / delete  reply

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

  9. 신촌출장마사지 2024/09/12 10:15  address  modify / delete  reply

    Thanks for sharing your thoughts on 하남출장마사지.
    Regards

  10. glow4d claim bonus 2024/09/13 16:32  address  modify / delete  reply

    I think what you said was actually very logical. However, what about this?
    suppose you added a little information? I ain't saying your information isn't
    solid, however what if you added something that grabbed people's attention? I mean 지나간
    삶 :: 에러 난곳을 알려주는 MiniDump 클래스 is kinda vanilla.
    You ought to peek at Yahoo's home page and note how
    they write article headlines to grab people interested.
    You might add a video or a related picture or two to get people interested about what you've got to say.

    In my opinion, it might bring your posts a little bit more interesting.

  11. 노원출장마사지 2024/09/14 14:57  address  modify / delete  reply

    Thanks for sharing your thoughts on 잠실출장마사지.
    Regards

  12. blocked drains dorchester 2024/09/17 06:30  address  modify / delete  reply

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

  13. 신림출장안마 2024/09/19 00:15  address  modify / delete  reply

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

  14. Panen33 2024/09/21 00:54  address  modify / delete  reply

    Thanls forr fіnally writing аbout >지나간 삶 :
    : 에러 난곳을 알려주는 MiniDump 클래스 <Loved it!

  15. 광명출장마사지 2024/09/22 17:21  address  modify / delete  reply

    I think that everything published was actually very logical.
    However, think on this, suppose you added a little information? I mean, I don't want to tell you how
    to run your website, however what if you added a title
    that grabbed people's attention? I mean 지나간 삶 :: 에러 난곳을 알려주는 MiniDump 클래스 is kinda vanilla.

    You might look at Yahoo's home page and see how they create
    post titles to get viewers to open the links.
    You might try adding a video or a related picture or two to get people excited about everything've got to say.
    In my opinion, it might bring your blog a little livelier.

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