简体   繁体   中英

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. 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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