|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
int _CrtSetReportMode( int reportType, int reportMode );
- Report type: _CRT_WARN, _CRT_ERROR, _CRT_ASSERT.
- New report mode or modes for reportType.
Upon successful completion, _CrtSetReportMode returns the previous report mode or modes for the report type specified in reportType. If an error occurs, the report mode or modes for reportType are not modified and _CrtSetReportMode returns –1.
_CrtSetReportMode specifies the output destination for _CrtDbgReport. Because the macros _ASSERT, _ASSERTE, _RPT, and _RPTF call _CrtDbgReport, _CrtSetReportMode specifies the output destination of text specified with those macros.
When _DEBUG is not defined, calls to _CrtSetReportMode are removed during preprocessing.
If you do not call _CrtSetReportMode to define the output destination of messages, the following defaults are in effect:
- Assertion failures and errors are directed to a debug message window.
- Warnings from Windows applications are sent to the debugger's output window.
- Warnings from console applications are not displayed.
The following table lists the report types defined in CRTDBG.H.
|_CRT_WARN||Warnings, messages, and information that does not need immediate attention.|
|_CRT_ERROR||Errors, unrecoverable problems, and issues that require immediate attention.|
|_CRT_ASSERT||Assertion failures (asserted expressions that evaluate to FALSE).|
The _CrtSetReportMode function assigns the new report mode specified in reportMode to the report type specified in reportType and returns the previously defined report mode for reportType. The following table lists the available choices for reportMode and the resulting behavior of _CrtDbgReport. These options are defined as bit-flags in CRTDBG.H.
|Report mode||_CrtDbgReport behavior|
|_CRTDBG_MODE_DEBUG||Writes the message to the debugger's output window.|
|_CRTDBG_MODE_FILE||Writes the message to a user-supplied file handle. _CrtSetReportFile should be called to define the specific file or stream to use as the destination.|
|_CRTDBG_MODE_WNDW||Creates a message box to display the message along with the Abort, Retry, and Ignore buttons.|
|_CRTDBG_REPORT_MODE||Returns reportMode for the specified reportType: |
Each report type can be reported using one, two, or three modes, or no mode at all. Therefore, it is possible to have more than one destination defined for a single report type. For example, the following code fragment causes assertion failures to be sent to both a debug message window and to stderr:
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW ); _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
In addition, the reporting mode or modes for each report type can be separately controlled. For example, it is possible to specify that a reportType of _CRT_WARN be sent to an output debug string, while _CRT_ASSERT be displayed using a debug message window and sent to stderr, as previously illustrated.
|_CrtSetReportMode||<crtdbg.h>||Win 98, Win Me, Win NT, Win 2000, Win XP|
For additional compatibility information, see Compatibility in the Introduction.
Debug versions of C run-time libraries only.
For a sample of how to use _CrtSetReportMode, see report.