Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

_CrtDbgReport, _CrtDbgReportW 

Generates a report with a debugging message and sends the report to three possible destinations (debug version only).


int _CrtDbgReport( 
   int reportType,
   const char *filename,
   int linenumber,
   const char *moduleName,
   const char *format [,
   argument] ... 
);
int _CrtDbgReportW( 
   int reportType,
   const wchar_t *filename,
   int linenumber,
   const wchar_t *moduleName,
   const wchar_t *format [,
   argument] ... 
);

Parameters

reportType

Report type: _CRT_WARN, _CRT_ERROR, and _CRT_ASSERT.

filename

Pointer to name of source file where assert/report occurred or NULL.

linenumber

Line number in source file where assert/report occurred or NULL.

moduleName

Pointer to name of module (.exe or .dll) where assert/report occurred.

format

Pointer to format-control string used to create the user message.

argument

Optional substitution arguments used by format.

For all report destinations, _CrtDbgReport and _CrtDbgReportW return –1 if an error occurs and 0 if no errors are encountered. However, when the report destination is a debug message window and the user clicks the Retry button, these functions return 1. If the user clicks the Abort button in the Debug Message window, these functions immediately abort and do not return a value.

The _RPT, _RPTF debug macros call _CrtDbgReport to generate their debug reports. The wide-character versions of these macros as well as _ASSERT[E], _RPTWn and _RPTFWn, use _CrtDbgReportW to generate their debug reports. When _CrtDbgReport or _CrtDbgReportW return 1, these macros start the debugger, provided that just-in-time (JIT) debugging is enabled.

_CrtDbgReport and _CrtDbgReportW can send the debug report to three different destinations: a debug report file, a debug monitor (the Visual Studio debugger), or a debug message window. Two configuration functions, _CrtSetReportMode and _CrtSetReportFile, are used to specify the destination or destinations for each report type. These functions allow the reporting destination or destinations for each report type to be separately controlled. For example, it is possible to specify that a reportType of _CRT_WARN only be sent to the debug monitor, while a reportType of _CRT_ASSERT be sent to a debug message window and a user-defined report file.

In Visual C++ 2005, _CrtDbgReportW is the wide-character version of _CrtDbgReport. All its output and string parameters are in wide-character strings; otherwise it is identical to the single-byte character version.

_CrtDbgReport and _CrtDbgReportW create the user message for the debug report by substituting the argument[n] arguments into the format string, using the same rules defined by the printf or wprintf functions. These functions then generate the debug report and determine the destination or destinations, based on the current report modes and file defined for reportType. When the report is sent to a debug message window, the filename, lineNumber, and moduleName are included in the information displayed in the window.

The following table lists the available choices for the report mode or modes and file and the resulting behavior of _CrtDbgReport and _CrtDbgReportW. These options are defined as bit flags in Crtdbg.h.

Report mode Report file _CrtDbgReport, _CrtDbgReportW behavior

_CRTDBG_MODE_DEBUG

Not applicable

Writes message to Windows OutputDebugString API.

_CRTDBG_MODE_WNDW

Not applicable

Calls Windows MessageBox API to create message box to display the message along with Abort, Retry, and Ignore buttons. If a user clicks Abort, _CrtDbgReport or _CrtDbgReport immediately aborts. If a user clicks Retry, it returns 1. If a user clicks Ignore, execution continues and _CrtDbgReport and _CrtDbgReportW return 0. Note that clicking Ignore when an error condition exists often results in "undefined behavior."

_CRTDBG_MODE_FILE

__HFILE

Writes message to user-supplied HANDLE, using the Windows WriteFile API and does not verify validity of file handle; the application is responsible for opening the report file and passing a valid file handle.

_CRTDBG_MODE_FILE

_CRTDBG_FILE_STDERR

Writes message to stderr.

_CRTDBG_MODE_FILE

_CRTDBG_FILE_STDOUT

Writes message to stdout.

The report can be sent to one, two, or three destinations or to no destination at all. For more information about specifying the report mode or modes and report file, see the _CrtSetReportMode and _CrtSetReportFile functions. For more information about using the debug macros and reporting functions, see Using Macros for Verification and Reporting.

If your application needs more flexibility than that provided by _CrtDbgReport and _CrtDbgReportW, you can write your own reporting function and hook it into the C run-time library reporting mechanism by using the _CrtSetReportHook function.

Routine Required header Compatibility

_CrtDbgReport

<crtdbg.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_CrtDbgReportW

<crtdbg.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

Libraries

Debug versions of C run-time libraries only.

// crt_crtdbgreport.c
#include <crtdbg.h>

int main() {
#ifdef _DEBUG
   CrtDbgReport(_CRT_ASSERT, NULL, NULL, "some module", NULL);
#endif
}

See crt_dbg2 for an example of how to change the report function.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.