다음을 통해 공유


_CrtSetReportMode

Specifies the destination or destinations for a specific report type generated by _CrtDbgReport and any macros that call _CrtDbgReport, _CrtDbgReportW, such as _ASSERT, _ASSERTE Macros, _ASSERT, _ASSERTE Macros, _RPT, _RPTF, _RPTW, _RPTFW Macros, and _RPT, _RPTF, _RPTW, _RPTFW Macros (debug version only).

int _CrtSetReportMode( 
   int reportType,
   int reportMode 
);

Parameters

  • reportType
    Report type: _CRT_WARN, _CRT_ERROR, and _CRT_ASSERT.

  • reportMode
    New report mode or modes for reportType.

Return Value

On successful completion, _CrtSetReportMode returns the previous report mode or modes for the report type specified in reportType. If an invalid value is passed in as reportType or an invalid mode is specified for reportMode, _CrtSetReportMode invokes the invalid parameter handler as described in Parameter Validation. If execution is allowed to continue, this function sets errno to EINVAL and returns -1. For more information, see errno, _doserrno, _sys_errlist, and _sys_nerr.

Remarks

_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, then 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.

Report type

Description

_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:

1   _CRTDBG_MODE_FILE

2   _CRTDBG_MODE_DEBUG

4   _CRTDBG_MODE_WNDW

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.

Requirements

Routine

Required header

Optional header

_CrtSetReportMode

<crtdbg.h>

<errno.h>

For more compatibility information, see Compatibility in the Introduction.

Libraries: Debug versions of C Run-Time Libraries only.

Example

See report Sample: C Run-Time Debugging Report Functions.

.NET Framework Equivalent

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

See Also

Concepts

Debug Routines