1 定义一个函数
void _invalid_parameter( const wchar_t * expression, const wchar_t * function, const wchar_t * file, int line, uintptr_t pReserved );
2 注册这个函数
_invalid_parameter_handler _set_invalid_parameter_handler(_invalid_parameter_handler pNew);
3 在程序开头的地方调用
_CrtSetReportMode(_CRT_ASSERT, 0);
一个简单的例子
#include <stdio.h> #include <stdlib.h> #include <crtdbg.h> void InvalidParameterHandler(const wchar_t* expression,const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) { wprintf(L"Invalid parameter detected in function %s." L" File: %s Line: %d ", function, file, line); wprintf(L"Expression: %s ", expression); } int main( ) { _invalid_parameter_handler oldHandler; oldHandler = _set_invalid_parameter_handler(InvalidParameterHandler); _CrtSetReportMode(_CRT_ASSERT, 0); //一个C的库函数的错误调用 ... }