|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|
Installs a client-defined reporting function by hooking it into the C run-time debug reporting process (debug version only).
New client-defined reporting function to hook into the C run-time debug reporting process.
_CrtSetReportHook allows an application to use its own reporting function into the C run-time debug library reporting process. As a result, whenever _CrtDbgReport is called to generate a debug report, the application's reporting function is called first. This functionality enables an application to perform operations such as filtering debug reports so it can focus on specific allocation types or send a report to destinations not available by using _CrtDbgReport. When _DEBUG is not defined, calls to _CrtSetReportHook are removed during preprocessing.
For a more robust version of _CrtSetReportHook, see _CrtSetReportHook2.
The _CrtSetReportHook function installs the new client-defined reporting function specified in reportHook and returns the previous client-defined hook. The following example demonstrates how a client-defined report hook should be prototyped:
int YourReportHook( int reportType, char *message, int *returnValue );
where reportType is the debug report type (_CRT_WARN, _CRT_ERROR, or _CRT_ASSERT), message is the fully assembled debug user message to be contained in the report, and returnValue is the value specified by the client-defined reporting function that should be returned by _CrtDbgReport. For a complete description of the available report types, see the _CrtSetReportMode function.
If the client-defined reporting function completely handles the debug message such that no further reporting is required, then the function should return TRUE. When the function returns FALSE, _CrtDbgReport is called to generate the debug report using the current settings for the report type, mode, and file. In addition, by specifying the _CrtDbgReport return value in returnValue, the application can also control whether a debug break occurs. For a complete description of how the debug report is configured and generated, see _CrtSetReportMode, _CrtSetReportFile, and _CrtDbgReport.
For more information about using other hook-capable run-time functions and writing your own client-defined hook functions, see Writing Your Own Debug Hook Functions.
If your application is compiled with /clr and the reporting function is called after the application has exited main, the CLR will throw an exception if the reporting function calls any CRT functions.
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, see Compatibility in the Introduction.
Debug versions of C run-time libraries only.
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.