我的CLog的实现

王朝vc·作者佚名  2006-01-08
宽屏版  字体: |||超大  

改编于一个老外的同名作品。

############ 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

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有