debuglog.cpp

来自「穿防火墙源代码」· C++ 代码 · 共 71 行

CPP
71
字号
/*	produce   logs
*/
#include 	<windows.h>
#include 	<stdio.h>
#include "debuglog.h"

#define  LOGFILENAME  "d:\\debuglog.txt"

HANDLE hlogFile; 

int  debugloginit()
{
	hlogFile = CreateFile(LOGFILENAME,    // file to open
                   GENERIC_READ | GENERIC_WRITE,          // open for reading
                   FILE_SHARE_READ,       // share for reading
                   NULL,                  // default security
                   OPEN_ALWAYS,         // existing file only
                   FILE_ATTRIBUTE_NORMAL, // normal file
                   NULL); 
	if (hlogFile == INVALID_HANDLE_VALUE) 
	{
		OutputDebugString("debugloginit  CreateFile  error\n");
	}
	else
	{
		SetFilePointer(hlogFile,0,NULL,FILE_END);
	}
	return 0;
}

int	 debuglogClose()
{
	if  (hlogFile!=NULL)
	{
		CloseHandle (hlogFile);
	}
	return 0;
}

int logprintf(LPCSTR lpszLog)
{
	
      DWORD dwBytesWritten; 
      int nSize;
      //va_list pArglist;
	BOOL fSuccess;

	if (lpszLog==NULL)
	{
		return(-1);
	}
      nSize=strlen(lpszLog);
	  if (nSize<1)
	  {
	  	return(-1);
	  }
	 fSuccess = WriteFile(hlogFile, 
                                 lpszLog, 
                                 nSize,
                                 &dwBytesWritten, 
                                 NULL); 
	if (!fSuccess) 
      {
           OutputDebugString("WriteFile failed with error.\n");
           return (-1);
       }
	return 0;
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?