当前位置: 首页 > news >正文

会计做帐模板网站广州网络公司策划

会计做帐模板网站,广州网络公司策划,火蝠电商代运营值得相信吗,琼中网站建设一,为什么需要dump文件 Windows客户端应用开发时,难免会遇到程序崩溃问题。当程序在Debug下运行崩溃时,我们可以直接定位到崩溃点。但是当程序打包成Release发布时,难免会遇到一些崩溃问题。一般遇到这样的崩溃,我们就…

一,为什么需要dump文件

    Windows客户端应用开发时,难免会遇到程序崩溃问题。当程序在Debug下运行崩溃时,我们可以直接定位到崩溃点。但是当程序打包成Release发布时,难免会遇到一些崩溃问题。一般遇到这样的崩溃,我们就需要使用 dump 文件加上符号表文件来进行调试程序。

二,如何生成dump文件

工欲善其事,必先利其器。这里直接给出一个CrashDump类,供各位大佬使用。在main函数实例化即可。生成不了dump文件你来打我~

三,CrashDump代码

CrashDump.h

#pragma once#include <Windows.h>
#include <Dbghelp.h>class CrashDump {
public:explicit CrashDump();~CrashDump();
private:static LONG WINAPI UnhandledExceptionFilter(struct _EXCEPTION_POINTERS* pExceptionInfo);
private:LPTOP_LEVEL_EXCEPTION_FILTER        m_oldExceptionFilter;
};

CrashDump.cpp

#include "CrashDump.h"
#include <ctime>
#include <string>
#include <sstream>
#include <assert.h>
#include <DbgHelp.h>
#include <shellapi.h>
#include <iostream>typedef BOOL(WINAPI *getUserModeExceptionProc)(LPDWORD);
typedef BOOL(WINAPI *setUserModeExceptionProc)(DWORD);typedef BOOL(WINAPI *MINIDUMPWRITEDUMP) (HANDLE hProcess,DWORD ProcessId,HANDLE hFile,MINIDUMP_TYPE DumpType,PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,PMINIDUMP_CALLBACK_INFORMATION CallbackParam);static std::wstring format(const wchar_t* pszFormat, ...) {wchar_t buffer[MAX_PATH] = { 0 };va_list ap;va_start(ap, pszFormat);int nCount = ::vswprintf_s(buffer, _countof(buffer), pszFormat, ap);va_end(ap);if (nCount < 0) {assert(false);return pszFormat;}return buffer;
}CrashDump::CrashDump(): m_oldExceptionFilter(NULL) {// 堆异常BOOL bRet = ::HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);::OutputDebugStringW(format(L"HeapSetInformation, bRet: <%lu, %lu>.\n", bRet, ::GetLastError()).c_str());// DEP策略bRet = ::SetProcessDEPPolicy(PROCESS_DEP_ENABLE | PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);::OutputDebugStringW(format(L"SetProcessDEPPolicy, bRet: <%lu, %lu>.\n", bRet, ::GetLastError()).c_str());//standard app-wide unhandled exception filterm_oldExceptionFilter = ::SetUnhandledExceptionFilter(UnhandledExceptionFilter);//fix for exceptions being swallowed inside callbacks (see KB976038)HMODULE hKernel32 = GetModuleHandle(TEXT("KERNEL32"));if (NULL == hKernel32) {::OutputDebugStringW(L"GetModuleHandle faled.\n");} else {DWORD dwFlags = 0;getUserModeExceptionProc procGetProcessUserModeExceptionPolicy;setUserModeExceptionProc procSetProcessUserModeExceptionPolicy;procGetProcessUserModeExceptionPolicy = (getUserModeExceptionProc)::GetProcAddress(hKernel32, "GetProcessUserModeExceptionPolicy");procSetProcessUserModeExceptionPolicy = (setUserModeExceptionProc)::GetProcAddress(hKernel32, "SetProcessUserModeExceptionPolicy");if (procGetProcessUserModeExceptionPolicy && procSetProcessUserModeExceptionPolicy) {if (procGetProcessUserModeExceptionPolicy(&dwFlags)) {bRet = procSetProcessUserModeExceptionPolicy(dwFlags & ~1);::OutputDebugStringW(format(L"GetProcessUserModeExceptionPolicy, bRet: %lu.\n", bRet).c_str());}::OutputDebugStringW(format(L"SetProcessUserModeExceptionPolicy, bRet: %lu, dwFlags: %lu.\n", bRet, dwFlags).c_str());}}
}CrashDump::~CrashDump() {if (NULL != m_oldExceptionFilter) {::SetUnhandledExceptionFilter(m_oldExceptionFilter);}
}LONG WINAPI CrashDump::UnhandledExceptionFilter(struct _EXCEPTION_POINTERS* pExceptionInfo) {//always break into a debugger if one is presentif (::IsDebuggerPresent()) {::OutputDebugStringW(L"IsDebuggerPresent return TRUE.\n");return EXCEPTION_CONTINUE_SEARCH;}static BOOL inExceptionHandler = FALSE;if (inExceptionHandler) {::OutputDebugStringW(L"Current function has crashed.Shit.\n");return EXCEPTION_CONTINUE_SEARCH;}inExceptionHandler = TRUE;WCHAR fullPath[MAX_PATH] = { 0 };DWORD pathLength = ::GetModuleFileNameW(NULL, fullPath, MAX_PATH);if (0 == pathLength) {::OutputDebugStringW(L"GetModuleFileNameW failed.\n");return EXCEPTION_CONTINUE_SEARCH;}LPCWSTR lastSlash = ::wcsrchr(fullPath, L'\\');if (NULL == lastSlash) {::OutputDebugStringW(L"wcsrchr return wrong.\n");return EXCEPTION_CONTINUE_SEARCH;}std::wstring exeDirPath(fullPath, lastSlash - fullPath + 1);WCHAR filePath[MAX_PATH] = { 0 };for (int i = 0; ; ++i) { // 避免同名 SYSTEMTIME sys_time = { 0 };::GetLocalTime(&sys_time);::swprintf_s(filePath, _countof(filePath) - 1, L"%s%04u_%02u_%02u_%02u_%02u_%02u_%d.dmp", exeDirPath.c_str(), sys_time.wYear, sys_time.wMonth, sys_time.wDay, sys_time.wHour, sys_time.wMinute, sys_time.wSecond, i);if (::GetFileAttributes(filePath) == INVALID_FILE_ATTRIBUTES) {break;}}HANDLE hFile = ::CreateFileW(filePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);if (INVALID_HANDLE_VALUE == hFile) {::OutputDebugStringW(L"CreateFileW failed.\n");return EXCEPTION_CONTINUE_SEARCH;}//load dbghelp dynamicallyHMODULE hDbgHelp = LoadLibraryW(L"DBGHELP");if (!hDbgHelp) {::OutputDebugStringW(L"LoadLibraryW DBGHELP failed.\n");return EXCEPTION_CONTINUE_SEARCH;}MINIDUMPWRITEDUMP fnMiniDumpWriteDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDbgHelp, "MiniDumpWriteDump");if (!fnMiniDumpWriteDump) {::OutputDebugStringW(L"GetProcAddress MiniDumpWriteDump failed.\n");::FreeLibrary(hDbgHelp);return EXCEPTION_CONTINUE_SEARCH;}MINIDUMP_TYPE dumpFlags = (MINIDUMP_TYPE)(MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithUnloadedModules | MiniDumpWithProcessThreadData);MINIDUMP_EXCEPTION_INFORMATION miniInfo = {0};miniInfo.ClientPointers = TRUE;miniInfo.ExceptionPointers = pExceptionInfo;miniInfo.ThreadId = ::GetCurrentThreadId();//generate a minidump if possibleif (fnMiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), hFile, dumpFlags, &miniInfo, NULL, NULL)) {WCHAR buffer[MAX_PATH] = { 0 };	::swprintf_s(buffer, _countof(buffer) - 1, L"Process has crashed.\nMinidump was saved to: \n\\%s\n", filePath);::OutputDebugStringW(buffer);// ::MessageBoxW(NULL, buffer, NULL, MB_ICONERROR | MB_OK);} else {::OutputDebugStringW(format(L"Minidump was saved failed: %hu.\n", ::GetLastError()).c_str());// ::MessageBoxW(NULL, format(L"Minidump was saved failed: %hu.\n", ::GetLastError()).c_str(), NULL, MB_ICONERROR | MB_OK);}::FreeLibrary(hDbgHelp);::CloseHandle(hFile);return EXCEPTION_CONTINUE_SEARCH;
}

四,在项目中调用

int main(int argc, char* argv[]) {
...CrashDump crashDump;  // 直接实例化即可
...
}

注意要用exe启动,不要用vs启动程序!

http://www.yayakq.cn/news/899673/

相关文章:

  • 怎样自己开网站赚钱亚马逊网站建设进度计划表
  • 工程技术研究中心网站建设要求深圳市南山区住房和建设局
  • 怀宁县住房与城乡建设局网站凡客诚品v
  • 怎么设置自己的网站那些网站可以找得到做货代的
  • 单页网站的区别建立网站公司有哪些
  • wordpress 做手机站WordPress建站收费
  • 推广平台网站热狗网小学校园网站怎么建设
  • 开发者模式怎么关闭vivo长春seo公司哪家好
  • 网站图片太多怎么优化更换域名wordpress
  • 新的网站怎么做seo普通网站怎么做h5
  • 设计很好看的网站在线代理免费
  • 企业网站管理系统教程网站关键词优化方式
  • gps建站步骤做网赌网站怎么推广
  • 企业网站建设东莞做购物网站适合的服务器
  • 阿里巴巴国际站怎么运营什么值得买 wordpress
  • 石油大学 网页设计与网站建设seo优化软件有哪些
  • 青海微信网站建设建站教程视频下载
  • 简洁商城网站模板my域名
  • html网页制作如何加入图片重庆seo职位
  • 南昌网站建设哪家好薇建设安全施工网络平台
  • 网站建设公司能赚钱吗wordpress禁用
  • 建设微商城网站php语言开发网站流程
  • 知春路网站建设公司成都网站排名提升
  • 长春网站制作方案定制免费自己制作app软件下载
  • 洛阳微信平台网站建设做烘培的网站有哪些
  • 免备案的网站百度一下就知道官方网站
  • 做软件下载网站软件项目管理的内容
  • 营销展示型网站模板手机看电影的网站建设
  • 青岛seo优化营商环境 提升服务效能
  • 学校网站建设问卷调查群晖搭建wordpress修改固定链接