⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntservapp.cpp

📁 本程序是实现中国移动中国联通的网关程序.代码比较完整.
💻 CPP
字号:
// NTService.cpp
// 
// This is the main program file containing the entry point.

#include "NTServApp.h"
#include "myservice.h"
BYTE isLogFile;
int main(int argc, char* argv[])
{
	FILE* pf;
	char lpFileName[MAX_PATH];
	char tchar[MAX_PATH];
	if(argc==2&&stricmp(argv[1],"-d")==0)
	{
		CMyService MyService("NTService");
		isLogFile=1;
		// Parse for standard arguments (here must be -d )
		MyService.ParseStandardArgs(argc, argv);
		// When we get here, the service has been stopped
		return 0;
	}


	GetModuleFileName(NULL,lpFileName,MAX_PATH);
	sprintf(strrchr(lpFileName,'\\')+1,"ServiceName.ini\0");
	pf=fopen(lpFileName,"r");
	if(pf==NULL)
	{
			AddLog("can not read from %s\n",lpFileName);
			fclose(pf);
			return 0;
	}
	else
	{
		if(fgets(tchar,MAX_PATH,pf)==NULL)
		{
			AddLog("can not read from %s\n",lpFileName);
			fclose(pf);
			return 0;
		}
		fgets(lpFileName,MAX_PATH,pf);//skim main service name;
		//now get islogfile flag:
 		if(fgets(lpFileName,64,pf)==NULL)isLogFile=0;
		else isLogFile=atoi(lpFileName);
		fclose(pf);	
		if(tchar[strlen(tchar)-1]<0x20)tchar[strlen(tchar)-1]=0;
	}
   // Create the service object
	CMyService MyService(tchar);

	// Parse for standard arguments (install, uninstall, version etc.)
	if (!MyService.ParseStandardArgs(argc, argv)) {

		// Didn't find any standard args so start the service
		// Uncomment the DebugBreak line below to enter the debugger
		// when the service is started.
		//DebugBreak();
		MyService.StartService();
	}

	// When we get here, the service has been stopped
	return MyService.m_Status.dwWin32ExitCode;

}
void AddLog(const char* format,...)
{
	FILE* pfLog;
	char current[36];
	char tp[36];
	struct _timeb timebuffer;
	char lpFileName[MAX_PATH];
	if(isLogFile==0)return;
	_strdate(current);
	_ftime(&timebuffer);
	strcpy(tp,ctime(&(timebuffer.time)));
	current[2]='_';
	current[5]=0;
	tp[strlen(tp)-1]=0;
	GetModuleFileName(NULL,lpFileName,MAX_PATH);
	sprintf(strrchr(lpFileName,'\\')+1,
	"Service%s_%.2s.txt\0",strrchr(tp,' ')+1,current);
	current[2]='-';
	tp[strrchr(tp,' ')-tp]=0;
	pfLog=fopen(lpFileName,"a");
	va_list args;
	va_start(args,format);
#if _DEBUG
	vfprintf(stdout,format,args);
#endif
	fprintf(pfLog,"%s<%s.%.3u> ",current,
		strrchr(tp,' ')+1,timebuffer.millitm);
	vfprintf(pfLog,format,args);
	va_end(args);
	fflush(pfLog);
	fclose(pfLog);
}

⌨️ 快捷键说明

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