0

I've tried this SO answer: How can I disable the debug assertion dialog on Windows?.

Still, no luck.

The code I'm using:

#include <Windows.h>
#include <crtdbg.h>
#include <cassert>

int test(int reportType, char* message, int* returnValue)
{
    return 0;
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    _CrtSetReportHook(&test);

    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
    _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
    _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);

    //_ASSERT(0);  // works as expected: no dialog appears
    assert(0); // The dialog appears

    return 0;
}

Maybe, there is something wrong with my system's config?

Alexander Dyagilev
  • 1,139
  • 1
  • 15
  • 43
  • [assert](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/assert-macro-assert-wassert?view=msvc-170) docs mention [_set_error_mode](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-error-mode?view=msvc-170#example) – dewaffled Jan 04 '23 at 22:35

1 Answers1

1

assert documentation notes _set_error_mode should be used:

To override the default output behavior regardless of the app type, call _set_error_mode to select between the output-to-stderr and display-dialog-box behavior.

From their example:

_set_error_mode(_OUT_TO_STDERR);
assert(2+2==5);
dewaffled
  • 2,850
  • 2
  • 17
  • 30