|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.|
After specifying _CRTDBG_MODE_FILE with, you can specify the file handle to receive the message text. _CrtSetReportFile is also used by to specify the destination of text (debug version only).
Report type: _CRT_WARN, _CRT_ERROR, and _CRT_ASSERT.
New report file for reportType.
On successful completion, _CrtSetReportFile returns the previous report file defined for the report type specified in reportType. If an invalid value is passed in for reportType, this function invokes the invalid parameter handler, as described in . If execution is allowed to continue, errno is set to EINVAL and the function returns _CRTDBG_HFILE_ERROR. For more information, see .
_CrtSetReportFile is used with thefunction to define the destination or destinations for a specific report type generated by _CrtDbgReport. When _CrtSetReportMode has been called to assign the _CRTDBG_MODE_FILE reporting mode for a specific report type, _CrtSetReportFile should then be called to define the specific file or stream to use as the destination. When is not defined, calls to _CrtSetReportFile are removed during preprocessing.
The following table shows a list of the available choices for reportFile and the resulting behavior of _CrtDbgReport. These options are defined as bit flags in Crtdbg.h.
- file handle
A handle to the file that will be the destination for messages. No attempt is made to verify the validity of the handle. You must open and close the handle to the file. For example:
HANDLE hLogFile; hLogFile = CreateFile("c:\\log.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, hLogFile); _RPT0(_CRT_WARN,"file message\n"); CloseHandle(hLogFile);
Writes message to stderr, which can be redirected as follows:
freopen( "c:\\log2.txt", "w", stderr); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); _RPT0(_CRT_ERROR,"1st message\n");
Writes message to stdout, which you can redirect.
Returns the current report mode.
The report file used by each report type can be separately controlled. For example, it is possible to specify that a reportType of _CRT_ERROR be reported to stderr, while a reportType of _CRT_ASSERT be reported to a user-defined file handle or stream.
|Routine||Required header||Optional header||Compatibility|
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003
For more compatibility information, seein the Introduction.
Libraries: Debug versions ofonly.