you can reference a text from MSDN It tell you how to debug a Windows service program that is similar to CGI. I had wrote a FileTrace function that like a TRACE MACRO in vc++. It can write trace infomation to a file. you can rewite it easily. see the definition of TRACE to know how MACRO TRACE work. ok. good luck.
// was there an error? was the expanded string too long? assert(nBuf >= 0); FILE* pOutPutFile = fopen(DEBUG_OUTPUT_FILE,"a+") ; assert(pOutPutFile); fwrite(szBuffer,sizeof(char),nBuf,pOutPutFile); fclose(pOutPutFile); va_end(args); } //////////////////////////////////////////////////////////////////////////void AfxClearTraceFile() {
It tell you how to debug a Windows service program that is similar to CGI.
I had wrote a FileTrace function that like a TRACE MACRO in vc++.
It can write trace infomation to a file.
you can rewite it easily. see the definition of TRACE to know how MACRO TRACE work.
ok.
good luck.
And the file trace.// zmjTrace.h: interface for the CTraceFile class.
//
//////////////////////////////////////////////////////////////////////#if !defined(AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_)
#define AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#ifdef
#include <stdio.h>
#include <assert.h>
#define OUTPUT_MAX_SIZE 512
#define DEBUG_OUTPUT_FILE "output.txt" //file debug to output to
#ifdef DEBUG //if debug
//////////////////////////////////////////////////////////////////////////
#define TRACE_OUTPUT AfxTraceOutput
///////////////////
#define TRACE_FILE AfxDebugToFile
#define TRACE_FILE_CLEAR AfxClearTraceFile()
//////////////////////////////////////////////////////////////////////////
#else
#define TRACE_OUTPUT DoNotingDTF
/////////////////////
#define TRACE_FILE DoNothingDTF
#define TRACE_FILE_CLEAR DoNotingCTF()
#endif
//////////////////////////////////////////////////////////////////////////
/// declare
void AfxTraceOutput(LPCTSTR lpszFormat,...);//////////////////////////////////////////////////////////////////////////
/// to file
void AfxDebugToFile(LPCTSTR lpszFormat,...);
inline void DoNothingDTF(LPCTSTR lpszFormat,...){};//////////////////////////////
// clear file
void AfxClearTraceFile(void );
inline void DoNotingCTF(void ){};//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/// implement
///
void AfxTraceOutput(LPCTSTR lpszFormat,...)
{
int nBuf;
TCHAR szBuffer[OUTPUT_MAX_SIZE];
memset(szBuffer,0,OUTPUT_MAX_SIZE*(sizeof(TCHAR)) );
va_list args;
va_start(args, lpszFormat);
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer)*(sizeof(TCHAR)), lpszFormat, args);
// was there an error? was the expanded string too long?
assert(nBuf >= 0);
OutputDebugString(szBuffer);
va_end(args);
}void AfxDebugToFile(LPCTSTR lpszFormat,...)
{
int nBuf;
TCHAR szBuffer[OUTPUT_MAX_SIZE];
memset(szBuffer,0,OUTPUT_MAX_SIZE*(sizeof(TCHAR)) );
va_list args;
va_start(args, lpszFormat);
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer), lpszFormat, args);
// was there an error? was the expanded string too long?
assert(nBuf >= 0); FILE* pOutPutFile = fopen(DEBUG_OUTPUT_FILE,"a+") ;
assert(pOutPutFile);
fwrite(szBuffer,sizeof(char),nBuf,pOutPutFile);
fclose(pOutPutFile);
va_end(args);
}
//////////////////////////////////////////////////////////////////////////void AfxClearTraceFile()
{
FILE* pOutPutFile = fopen(DEBUG_OUTPUT_FILE,"w+") ;
assert(pOutPutFile);
fclose(pOutPutFile);}#endif // !defined(AFX_TRACEFILE_H__B31699F5_714D_418A_A1D7_FF5A5F1927CE__INCLUDED_)