看了下邮件的发送与接收,了解了这方面知识,写一个帖子。
1、设置捕获
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE h0, LPTSTR lpCmdLine, int nCmdShow)
{
BOOL bRet;
MSG msg;
HWND hwndFrame;
[B][COLOR="Red"] g_previousFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);[/COLOR][/B]
//_CrtSetBreakAlloc(58);
InitCommonControls();
g_hInst = hInst;
//hModUxTheme = LoadLibrary(L"uxtheme.dll");
//注册框架窗口类
//创建框架窗口
//消息泵
//if (hModUxTheme)
//FreeLibrary(hModUxTheme);
_CrtDumpMemoryLeaks();
return (int) bRet;
}
LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)
{
SYSTEMTIME time;
LONG lRet = EXCEPTION_CONTINUE_SEARCH;
//HRESULT hr ;
int end;
GetLocalTime(&time);
char acBuf[MAX_PATH] = {0};
// Build a string showing the date and time.
//Returns the number of characters written to the buffer, excluding any terminating NULL characters. A negative value is returned if an error occurs.
end = wnsprintfA(acBuf, MAX_PATH, "%d%02d%02d%02d%02d%02d.dmp",time.wYear,
time.wMonth, time.wDay,time.wHour, time.wMinute,time.wSecond);
if(end > 0)
{
HANDLE hFile;
char szBugFile[MAX_PATH+1] = {0};
GetModuleFileNameA(NULL,szBugFile,MAX_PATH + 1);
PathRemoveFileSpecA(szBugFile);
PathAppendA(szBugFile,acBuf);
hFile = CreateFileA(szBugFile,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
;
//WriteLog(_T("ExceptionInfo"),_T("CreateFile"),_T("-1"));
}else{
BOOL (__stdcall *fnMiniDumpWriteDump)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE,
PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,PMINIDUMP_CALLBACK_INFORMATION);
//typedef BOOL (__stdcall *MiniDumpWriteDumpProc)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE,
//PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,PMINIDUMP_CALLBACK_INFORMATION);
HINSTANCE hinstLib;
//BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
//MiniDumpWriteDumpProc fnMiniDumpWriteDump;
hinstLib = LoadLibrary(TEXT("DbgHelp.dll"));
if(hinstLib)
{
(FARPROC&)fnMiniDumpWriteDump = ::GetProcAddress(hinstLib, "MiniDumpWriteDump");
//fnMiniDumpWriteDump = ( MiniDumpWriteDumpProc)::GetProcAddress(hinstLib, _T("MiniDumpWriteDump"));
if(fnMiniDumpWriteDump )
{
MINIDUMP_EXCEPTION_INFORMATION info;
info.ThreadId = ::GetCurrentThreadId();
info.ExceptionPointers = pExceptionInfo;
info.ClientPointers = FALSE;
BOOL bOk = fnMiniDumpWriteDump(::GetCurrentProcess,::GetCurrentProcessId(),hFile,MiniDumpNormal,&info,NULL,NULL);
if(bOk == FALSE)
WriteLog(_T("ExceptionInfo"),_T("MiniDumpWriteDump"),_T("error(0x%x)"),GetLastError());
HWND hBug = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_BUGDLG), NULL, (DLGPROC)BugDlgProc,(LPARAM)&info);
SetWindowLong(hBug,GWL_USERDATA,(LONG)szBugFile);
ShowWindow(hBug,SW_NORMAL);
BOOL bRet;
MSG msg;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
break;
}
else if (!IsWindow(hBug) || !IsDialogMessage(hBug, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
lRet = EXCEPTION_EXECUTE_HANDLER;
}else
WriteLog(_T("ExceptionInfo"),_T("MiniDumpWriteDump"),_T("Failed to get"));
FreeLibrary(hinstLib);
}else
WriteLog(_T("ExceptionInfo"),_T("DbgHelp.dll"),_T("Failed to load"));
}
CloseHandle(hFile);
//SAFE_DELETE(g_pszBugFile);
}
//if(g_previousFilter)
// return g_previousFilter(pExceptionInfo);
//else
return lRet;
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课