Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266570
  • 博文数量: 55
  • 博客积分: 2030
  • 博客等级: 大尉
  • 技术积分: 737
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-13 18:06
文章分类

全部博文(55)

文章存档

2011年(2)

2010年(7)

2009年(17)

2008年(29)

我的朋友

分类: C/C++

2008-10-10 23:32:48

自制_trace, 在非mfc程序中调用,在ouput窗口中输出.
 
 

//debug.h

#ifndef __DEBUG_H__
#define __DEBUG_H__

#include <tchar.h>


#ifdef _DEBUG

void _trace(TCHAR * szFormat, ...);

#endif

#ifdef _DEBUG

#define TRACE _trace

#endif

#endif

 

//file debug.cpp
#ifdef _DEBUG

#include <stdio.h>
#include <stdarg.h>
#include <windows.h>

#include "debug.h"
void _trace(TCHAR * szFormat, ...)
{
    TCHAR szBuffer [1024] ;
    va_list pArgList ;

    va_start (pArgList, szFormat) ;

    _vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
                 szFormat, pArgList) ;

    va_end (pArgList) ;

    OutputDebugString(szBuffer);

}
#endif

 

//main.cpp

#include <stdio.h>
#include <windows.h>
#include "debug.h"

int main()
{
    _trace(TEXT ("The screen is %d pixels wide by %d pixels high."),
        3, 4);
    return 0;
}

阅读(1700) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~