DgbView 调试类

来源:互联网 发布:力和能量的公式知乎 编辑:程序博客网 时间:2024/06/06 02:47

#ifndef __MYDBG_HEADER_FILE_
#define __MYDBG_HEADER_FILE_

#define __DBG_RELEASE


#ifdef __DBG_RELEASE
void DbgPrintfA(LPCSTR lpFmt,...);
void DbgPrintfW(LPCWSTR lpFmt,...);
void DbgDumpBuf(const void* pBuf,int nSize);
#pragma message("Build with DbgPrintf information.Remove __DBG_RELEASE to avoid this message")
#else
#define DbgPrintfA
#define DbgPrintfW
#define DbgDumpBuf
#endif


#endif

==========

#include "stdafx.h"
#include <windows.h>
#include "MyDbg.h"
#define __DBG_RELEASE

#ifdef __DBG_RELEASE
void DbgPrintfA(LPCSTR lpFmt,...)
{
 char szBuf[1024];
 memset(szBuf,0,1024);
 va_list argList;
 va_start(argList, lpFmt);  
 wvsprintfA(szBuf,lpFmt, argList);
 va_end(argList);  
 OutputDebugStringA(szBuf);
}

void DbgPrintfW(LPCWSTR lpFmt,...)
{
 WCHAR szBuf[1024];
 memset(szBuf,0,1024);
 va_list argList;
 va_start(argList, lpFmt);  
 wvsprintfW(szBuf,lpFmt, argList);
 va_end(argList);  
 OutputDebugStringW(szBuf);
}

void DbgDumpBuf(const void* pData,int nSize)
{
 PBYTE pBuf = (PBYTE)pData;
 char szMsg[512];
 memset(szMsg,0,512);
 char* p = szMsg;
 for(int i=0;i<nSize;i++)
 {  
  wsprintfA(p,"%02X ",pBuf[i]);
  p+=3;
  if((i!=0)&&(i%7==0))
  {
   DbgPrintfA(szMsg);
   memset(szMsg,0,512);
   p = szMsg;
  }
 }
}
#endif

原创粉丝点击