简体   繁体   English

如何在程序崩溃时仅关闭程序,而没有任何警告屏幕等…C ++ Windows

[英]How to just close a program when it crashes, without any warning screens, etc … C++ Windows

I'm doing a Windows program with JUCE and C++, and I want it to just close when it crashes. 我正在用JUCE和C ++做一个Windows程序,我希望它在崩溃时可以关闭。 Right now it shows the crash dialog and you have to hit close. 现在它显示崩溃对话框,您必须单击关闭。 I don't want to show anything, just to close it. 我不想显示任何内容,只是要关闭它。 Is it possible? 可能吗?

Thank you. 谢谢。

Found what I needed, and it works perfectly. 找到了我需要的东西,并且效果很好。

#include <windows.h>
#include <rtcapi.h>
int exception_handler(LPEXCEPTION_POINTERS p)
{
    printf("Exception detected during the unit tests!\n");
    exit(1);
}
int runtime_check_handler(int errorType, const char *filename, int linenumber, const char *moduleName, const char *format, ...)
{
    printf("Error type %d at %s line %d in %s", errorType, filename, linenumber, moduleName);
    exit(1);
}

int main()
{
    DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
    SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler); 
    _RTC_SetErrorFunc(&runtime_check_handler);

    // Run your tests here

    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM