gpt4 book ai didi

Windows - 防止崩溃 "Checking for a solution..."和 "Restarting the program..."

转载 作者:可可西里 更新时间:2023-11-01 13:26:45 31 4
gpt4 key购买 nike

这可能不是一个纯粹与编程相关的问题,但我在开发过程中经常遇到这个问题。当我的应用程序崩溃并且我选择终止它时,Windows 会自动弹出“正在检查解决方案...”对话框。当我点击上面的取消按钮时,我会看到另一个对话框,上面写着“重新启动程序......”有没有办法防止这种行为?当我停止一个应用程序时,我更希望它被悄无声息地杀死。如果平台很重要,我会使用 Windows 7。

最佳答案

尽管 Microsoft 建议使用仅在 Windows Vista 及更高版本上可用的更新的替换 API,但有一个 API 适用于从 XP 开始的所有 Windows 版本:AddERExcludedApplication() .此函数采用不带路径信息的模块名称(例如,“myprogram.exe”),将禁用错误报告。

只有 Windows Vista 及更高版本可用的新方法是调用 WerAddExcludedApplication() function .此 API 允许您指定是否应更改 HKEY_CURRENT_USER 注册表配置单元或 HKEY_LOCAL_MACHINE 注册表配置单元。如果HKLM设置失败一定要为HKCU设置这个,比如:

typedef BOOL (*ADD_MER_EXCLUDED_APP_XP)     (PCWSTR);typedef BOOL (*ADD_MER_EXCLUDED_APP_VISTA)  (PCWSTR, BOOL);bool disable_microsoft_error_reporting(PCWSTR wz_app){    const WCHAR * const WZ_MER_DLL_XP       = L"faultrep.dll";    const char  * const SZ_MER_PROC_XP      = "AddERExcludedApplicationW";    const WCHAR * const WZ_MER_DLL_VISTA    = L"wer.dll";    const char  * const SZ_MER_PROC_VISTA   = "WerAddExcludedApplicationW";    const int   WER_EXCLUDE_FOR_ALL_USERS   = TRUE;    const int   WER_EXCLUDE_FOR_THIS_USER   = FALSE;    HANDLE      hlib_error_reports_xp       = NULL;    HANDLE      hlib_error_reports_vista    = NULL;    ADD_MER_EXCLUDED_APP_XP     add_mer_excluded_app_xp     = NULL;    ADD_MER_EXCLUDED_APP_VISTA  add_mer_excluded_app_vista  = NULL;    bool        success                     = false;    // First, attempt the API that has been around since XP.    hlib_error_reports_xp = LoadLibrary(WZ_MER_DLL_XP);    if (hlib_error_reports_xp)    {        add_mer_excluded_app_xp = (ADD_MER_EXCLUDED_APP_XP)GetProcAddress(hlib_error_reports_xp, SZ_MER_PROC_XP);        if (add_mer_excluded_app_xp)            success = add_mer_excluded_app_xp(wz_app);        FreeLibrary(hlib_error_reports_xp);        hlib_error_reports_xp   = NULL;        add_mer_excluded_app_xp = NULL;        if (success)            return true;    }    // That did not succeed.  Attempt the Vista API.    hlib_error_reports_vista = LoadLibrary(WZ_MER_DLL_VISTA);    if (hlib_error_reports_vista)    {        add_mer_excluded_app_vista = (ADD_MER_EXCLUDED_APP_VISTA)GetProcAddress(hlib_error_reports_vista, SZ_MER_PROC_VISTA);        if (add_mer_excluded_app_vista)        {            success = (S_OK == add_mer_excluded_app_vista(wz_app, WER_EXCLUDE_FOR_ALL_USERS));            if (!success)                success = (S_OK == add_mer_excluded_app_vista(wz_app, WER_EXCLUDE_FOR_THIS_USER));        }           FreeLibrary(hlib_error_reports_vista);        hlib_error_reports_vista    = NULL;        add_mer_excluded_app_vista  = NULL;        if (success)            return true;    }    // Nothing worked.  Fail.    return false;}

为了进一步减少 WER 组件的执行,实现未处理的异常过滤器并将其传递给:SetUnhandledExceptionFilter() function .要分流 WER,您的过滤器绝不能返回 EXCEPTION_CONTINUE_SEARCHEXCEPTION_EXECUTE_HANDLER

实现 SetUnhandledExceptionFilter() 函数的缺点之一是它会干扰即时调试。

您提到您希望该应用程序被“悄无声息地杀死”。在那种情况下:

LONG WINAPI global_exception_filter(struct _EXCEPTION_POINTERS *exception_info){    ExitProcess(0xDEDD000D);}int WINAPI WinMain(    HINSTANCE _hinstance,    HINSTANCE hinstance_prev,    LPSTR sz_cmd_line,    int cmd_show){    SetUnhandledExceptionFilter(global_exception_filter);    /* ... */}

将导致应用程序在出现未处理的异常时立即消失。注意,返回的退出代码是个人喜好问题。

关于Windows - 防止崩溃 "Checking for a solution..."和 "Restarting the program...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698342/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com