After specifying _CRTDBG_MODE_FILE with _CrtSetReportMode, you can specify the file handle to receive the message text. Also used by _CrtDbgReport to specify the destination of text (debug version only).
_HFILE _CrtSetReportFile( int reportType, _HFILE reportFile );
- Report type: _CRT_WARN, _CRT_ERROR, _CRT_ASSERT.
- New report file for reportType.
Upon successful completion, _CrtSetReportFile returns the previous report file defined for the report type specified in reportType. If an error occurs, the report file for reportType is not modified and _CrtSetReportFile returns _CRTDBG_HFILE_ERROR.
_CrtSetReportFile is used in conjunction with the _CrtSetReportMode function 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 _DEBUG is not defined, calls to _CrtSetReportFile are removed during preprocessing.
The following is 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. stderr 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. You can redirect stdout.
- 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.
|_CrtSetReportFile||<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 _CrtSetReportFile, see report.