1. MiniDump.h
2. MiniDump.cpp
3. 사용예제
#pragma once
class CMiniDump
{
public:
static BOOL Begin(VOID);
static BOOL End(VOID);
};
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;
}
#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 파일을 실행시킨후 디버깅 해주면 에러난곳에 멈춘다.
//////////////////////////////////////////////////////////////////////
{
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 파일을 실행시킨후 디버깅 해주면 에러난곳에 멈춘다.
//////////////////////////////////////////////////////////////////////
댓글을 달아 주세요
많은 도움되었습니다. 감사합니다. ^.^v
감사합니당 ㅠㅠ
감사합니다 ㅠㅠ
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.
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.
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.
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.