📄 log2file.h
字号:
//log2file.h
//use #define UseLogging to enable logging
#define UseLogging //to enable logging to file
//global
char logFileName[MAX_PATH];
TCHAR logFileNameW[MAX_PATH];
//bool FirstStart = FALSE;
void Add2Log(TCHAR);
void Add2Log(LPSTR);
void Add2Log(TCHAR *txt, BOOL bLogTime);
void Add2Log(char *txt, BOOL bLogTime);
void Add2Log (TCHAR *lpszFormat, ...);
void Add2LogWtime (TCHAR *lpszFormat, ...);
int writefile(LPTSTR);
int newfile(LPSTR);
int newfile(TCHAR);
int appendfile(LPSTR);
//=================================================================================
//implementation
//=================================================================================
//-----------------------------------------------------------------------
// Add2Log - Add string to the the file
//
void Add2Log (TCHAR *lpszFormat, ...) {
int nBuf;//, i;
TCHAR szBuffer[512];
va_list args;
va_start(args, lpszFormat);
nBuf = vswprintf(szBuffer, lpszFormat, args);
Add2Log(szBuffer, false);
va_end(args);
}
//-----------------------------------------------------------------------
// Add2Log - Add string to the the file
//
void Add2LogWtime (TCHAR *lpszFormat, ...) {
int nBuf;//, i;
TCHAR szBuffer[512];
va_list args;
va_start(args, lpszFormat);
nBuf = vswprintf(szBuffer, lpszFormat, args);
Add2Log(szBuffer, true);
va_end(args);
}
//-----------------------------------------------------------------------
// appendfile - set the global filename to append text
//
int appendfile(char *filename)
{
//store the filename to use in char and tchar
sprintf(logFileName, filename);
mbstowcs(logFileNameW, logFileName, sizeof(logFileName)*sizeof(logFileName[0]));
FILE *fp;
fp = fopen(logFileName, "a+");
fclose(fp);
return 0;
}
int newfile(char *filename)
{
//store the filename to use in char and tchar
sprintf(logFileName, filename);
mbstowcs(logFileNameW, logFileName, sizeof(logFileName)*sizeof(logFileName[0]));
FILE *fp;
fp = fopen(logFileName, "w+");
fclose(fp);
return 0;
}
int newfile(TCHAR *filename)
{
//store the filename to use in char and tchar
TCHAR logFileNameW[MAX_PATH];
wsprintf(logFileNameW, filename);
wcstombs(logFileName, logFileNameW, sizeof(logFileNameW)*sizeof(logFileNameW[0]));
FILE *fp;
fp = fopen(logFileName, "w+");
fclose(fp);
return 0;
}
int writefile(TCHAR *filetext)
{
#ifdef UseLogging
/* File Write Function, written by professor chemicalX */
FILE *fp; /* Declare FILE structure */
TCHAR szTemp[1500];
char szTempA[1500];
wsprintf(szTemp, L"%s", filetext);
wcstombs(szTempA, szTemp, sizeof(szTemp)/sizeof(TCHAR));
fp = fopen(logFileName, "a+");
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/* First of we open the file supplied by the filename paremeter */
/*
* in the "a+" mode for appending, so if it doesnt exist its created.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -