我已经尝试了这个答案:我如何在Windows上禁用调试断言对话框?
还是不走运。
我使用的代码:
#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;
}
也许,我的系统配置有问题?
断言文档注释_set_error_mode应该使用:
要覆盖默认的输出行为,无论应用程序类型如何,调用_set_error_mode在输出到标准错误和显示对话框行为之间进行选择。
从他们的例子:
_set_error_mode(_OUT_TO_STDERR);
assert(2+2==5);