一般调用API函数的时候会判断返回值,可这样要判断返回值,如果有隐形错误我们就要单步调试,要怎么办才不单步调试呢?想了个办法,请大家看下下面这段根据我的理论手写构造的一段代码(请自己修改为正确的代码).
//软件功能Bug调试器机制 By:邓韬
#include <stdio.h>
#include <windows.h>
//宏定义形式
#define isCallSuccessful(pFile,nLine,pFunc,nFuncRet,nCode){\
if((unsigned long)nFuncRet!=(unsigned long)nCode){\
printf("FILE:%s Line:%d Function:%s Error:%s",(char*)pFile,(unsigned long)nLine,(char*)pFunc,nFuncRet);\
return FALSE;}\
else{\
return TRUE;}\
}
//函数形式,功能大概与上面一样.
void asynLogger::isCallFormat(const char *pMsgFmt,...)
{
char pMsgBuffer[constants::kMaxMessageSize];
va_list arglist;
va_start(arglist, pMsgFmt);
asynLogger::_saveMessageTime();
asynLogger::_saveMessageLength(pMsgFmt,pMsgBuffer,vsnprintf(pMsgBuffer,sizeof(pMsgBuffer),pMsgFmt,arglist));
asynLogger::_saveNewLine();
va_end(arglist);
}
//--------------------------------------------------------------------
int main(int argv,char* argc[])
{
if(isCallSuccessful(__FILE__,__FILE__,__FUNCTION__,MessageBoxA(NULL,"is ok?","debug",MB_YESNO),IDYES)==TRUE)
{
printf("function success!\n");
}
return EXIT_SUCCESS;
}
谢谢观看!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课