我的CLog的实现
改编于一个老外的同名作品。
############ log.h #################
//===========================================================================
//
// HomeWork from Belgium Not licensed software
// 1999 - 2000 No rights reserved
//
//===========================================================================
//
// Project/Product : Iconizer DLL
// FileName : log.h
// Author(s) : Bart Gysens
//
// Description : Declaration of CLog class
//
// Classes : CLog
//
// Information :
// Compiler(s) : Visual C++ 6.0
// Target(s) : Windows 95/98 and Windows NT (x86)
// Editor : Visual C++ 6.0 internal editor
//
// History
// Vers. Date Aut. Type Description
// ----- ---------- ---- ------- -----------------------------------------
// 1.00 22 05 1999 BG Create Original
// 1.01 20 12 2000 hewen Add
// 1.03 24 10 2001 hewen Add
// 1.04 10 06 2003 hewen Add
//===========================================================================
#ifndef _LOG_H_INCLUDED__
#define _LOG_H_INCLUDED__
//===========================================================================
// Macros and typedefs
//===========================================================================
//===========================================================================
//
// Class : CLog
// Author(s) : Bart Gysens
//
// Description : Declaration of the CLog class
//
// Comments : none
//
// History : 1.00 : Create
// 1.01 : hewen Add
// 1.03 : hewen Add
// 1.04 : hewen Add
//===========================================================================
class CLog
{
// Member functions
public:
CLog();
public:
static void PutLog( LPCTSTR pFmt, ... );
//1.01
static void SetFile(LPCTSTR FileName);
//1.03
static void Delete(void);
//1.04
static void PutLogBinary(VOID *pMem,DWORD Length,BOOL bTxt);
static void MessageBox( LPCTSTR pFmt, ... );
};
#endif // _LOG_H_INCLUDED__
############ log.cpp #################
//===========================================================================
//
// HomeWork from Belgium Not licensed software
// 1999 - 2000 No rights reserved
//
//===========================================================================
//
// Project/Product : Iconizer DLL
// FileName : log.cpp
// Author(s) : Bart Gysens
//
// Description : Declaration of CLog class
//
// Classes : CLog
//
// Information :
// Compiler(s) : Visual C++ 6.0
// Target(s) : Windows 95/98 and Windows NT (x86)
// Editor : Visual C++ 6.0 internal editor
//
// History
// Vers. Date Aut. Type Description
// ----- ---------- ---- ------- -----------------------------------------
// 1.00 22 05 1999 BG Create Original
// 1.01 20 12 2000 hewen Add
// 1.03 24 10 2001 hewen Add
// 1.04 16 06 2003 hewen Add My BirthDay
//===========================================================================
#include "stdafx.h"
#include "stdio.h"
//1.01
#include "stdlib.h"
#include "log.h"
//===========================================================================
// Macros and typedefs
//===========================================================================
//===========================================================================
//
// Class : CLog
// Author(s) : Bart Gysens
//
// Description : Declaration of the CLog class
//
// Comments : none
//
// History : 1.00 : Create
// 1.01 : hewen Add
// 1.03 : hewen Add
// 1.04 : hewen Add
//===========================================================================
//1.01
static char gLogFileName[_MAX_PATH] = "LOG.TXT";
CLog::CLog()
{
}
void CLog::PutLog( LPCTSTR pFmt, ... )
{
//1.02
#ifdef _DEBUG_LOG
FILE * pFile;
//1.01
pFile = fopen( gLogFileName, "ab" );
//1.00
// pFile = fopen( "C:\\LOG.TXT", "a" );
if ( pFile != NULL )
{
va_list arg;
va_start( arg, pFmt );
vfprintf( pFile, pFmt, arg );
va_end( arg );
fclose( pFile );
}
#endif
}
//1.01
void CLog::SetFile(LPCTSTR FileName)
{
//1.02
#ifdef _DEBUG_LOG
strncpy(gLogFileName,FileName,_MAX_PATH);
#endif
}
//1.03
void CLog::Delete(void)
{
#ifdef _DEBUG_LOG
DeleteFile(gLogFileName);
#endif
}
//1.04
void CLog::PutLogBinary(VOID *pMem,DWORD Length,BOOL bTxt)
{
#ifdef _DEBUG_LOG
FILE * pFile;
int Row, r, i, j;
if(pMem == NULL || Length <= 0)
return;
pFile = fopen( gLogFileName, "ab" );
unsigned char *P = (unsigned char *)pMem;
unsigned char txtBuff[16];
if ( pFile != NULL )
{
if(!bTxt)
{
fwrite(P,Length,1,pFile);
}
else
{
Row = Length / 16;
r = Length % 16;
for(i=0;i<Row;i++)
{
fprintf(pFile,"%04x:",i);
for(j=0;j<16;j++)
{
fprintf(pFile,"%c%02X",(j == 8 ? ´-´ : ´ ´),*P);
txtBuff[j] = isgraph(*P) ? *P : ´.´;
P ++;
}
fprintf(pFile," | ");
fwrite(txtBuff,16,1,pFile);
fprintf(pFile,"\r\n");
}
fprintf(pFile,"%04x:",Row);
for(i=0;i<16;i++)
{
if(i < r)
{
fprintf(pFile,"%c%02X",(j == 8 ? ´-´ : ´ ´),*P);
txtBuff[j] = isgraph(*P) ? *P : ´.´;
}
else
{
fprintf(pFile," ");
txtBuff[j] = ´ ´;
}
P ++;
}
fprintf(pFile," | ");
fwrite(txtBuff,16,1,pFile);
fprintf(pFile,"\r\n");
}
fprintf(pFile,"\r\n");
fclose( pFile );
}
#endif
}
//1.04
#include "windows.h"
void CLog::MessageBox( LPCTSTR pFmt, ... )
{
#ifdef _DEBUG_LOG
char buff[1024];
buff[0] = 0;
va_list arg;
va_start( arg, pFmt );
vsprintf( buff, pFmt, arg );
va_end( arg );
AfxMessageBox(buff,MB_OK,0);
#endif
}
- · 学Java,观GP
- · 怎样写一个 NT 服务程序
- · 代码优化试验——短循环优化(上)
- · 代码优化试验——短循环优化(下)
- · =========<C++未眠夜---我学习C++的心路历程>========
- · BOOK
- · 读《Efficient C++》疑惑
- · C++中的预处理(下)
- · DSP v1.0--序列化和反序列化对象和DNS v1.0--得到域的邮件服务器
- · C++入门解惑(0)——序
- · 代码自动完成、文档自动生成、提高开发效率----介绍VcExtend
- · “瑜珈山夜话”---序
- · C++入门解惑(1)——浅析cout
- · VC6使用#pragma warning的一点经验
- · 如何在一个容器中放入不同对象(续)
- · “瑜珈山夜话” ----内存分配(一)
- · 最简单的屏幕拷贝程序(象素拷贝)
- · vc入门宝典(十)
- · Win32学习笔记 第六章 程序6-3 Typer 说明
- · 自动建库的安装程序制作方法
- · “瑜珈山夜话” ----内存分配(二)
- · 让Windows 2000/XP中的任意窗口透明起来
- · 不比不知道,一比吓一跳!
- · “瑜珈山夜话” ----内存分配(三)
- · WTL体系结构(3)
- · 控制台程序的事件處理
- · 深入DCOM之DCOM的发展史
- · Windows程序效率
- · C++入门解惑(2)——初探指针(上)
- · 读好文章,快速理解COM组件知识,10分钟深刻阅读,获得超过2000元的培训
- · WTL的消息机制
- · DirectShow应用——支持DVD播放
- · 浏览器集成教学 自定义浏览器
- · 计算机科学与技术学生学习基础材料参考
- · 关于std::list的sort函数在VC6下的修正
- · 数据结构学习(C++)——线性链式结构总结(代后记)【2】
- · 深入DCOM之STA
- · 在COM中使用数组参数-数组指针
