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

📄 serviceapp.cpp

📁 VC后台服务的模板框架
💻 CPP
字号:
// ServiceApp.cpp: implementation of the CServiceApp class.
//
//////////////////////////////////////////////////////////////////////
#define _SOCKET_DEF_

#include "stdafx.h"
#include "ServiceApp.h"
#include <afxtempl.h>
#include <afxmt.h>


CServiceApp theApp;


void DEBUGINFO(const char *format,...);

CString gStr_dsname,gStr_username,gStr_passwd;
int gInt_dtype;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void DEBUGINFO(const char *format,...)
 {
	
 
 	char tStr_Info[1024],tStr_t[1024];

	memset(tStr_Info,0,1024);
	memset(tStr_t,0,1024);
 	
 	va_list args;

 	va_start(args,format);
 
 	vsprintf(tStr_Info,format,args);
 
 	va_end(args);
	sprintf(tStr_t,"[Radius计费]%s",tStr_Info);

    ::OutputDebugString(tStr_t);

 
}

CServiceApp::CServiceApp()
	: CNTService(TEXT("ADIS Server"), TEXT("Vtion ADIS INFORM 1.0"))
{
	m_dwServiceType=SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS;
	m_pszDependencies=m_szDependencies;
}

CServiceApp::~CServiceApp()
{
	
}

BOOL CServiceApp :: InitInstance() {
	RegisterService(__argc, __argv);
	//::CoInitialize(NULL);
	return FALSE;
}

BOOL g_bRun=FALSE;

void CServiceApp :: Run( DWORD, LPTSTR *)
{		
	// args not used in this small example
	// report to the SCM that we're about to start
	ReportStatus(SERVICE_START_PENDING);
	
	// report SERVICE_RUNNING immediately before you enter the main-loop
	// DON'T FORGET THIS!
	ReportStatus(SERVICE_RUNNING);

	g_bRun=TRUE;	
	int tInt_Ret=0;

	char tStr_ConfigFile[50];
	memset(tStr_ConfigFile,0,50);
	::GetWindowsDirectory(tStr_ConfigFile,30);
	strcat(tStr_ConfigFile,"\\vtion.ini");
 	this->ReadConfigFile(tStr_ConfigFile);

	//读系统参数
	while(g_bRun)
	{
		SqlServer *tObj_Sql=new SqlServer();
		if(tObj_Sql->IsConnected())
		{
			delete tObj_Sql;
			break;
		}
		delete tObj_Sql;
		Sleep(10000);
	}
	while(g_bRun)
	{
		Sleep(10000000);
	}
}


void CServiceApp :: Stop() 
{
	ReportStatus(SERVICE_STOP_PENDING);

	g_bRun=FALSE;
}

int CServiceApp::ExitInstance()
{
	//::CoUninitialize();
	return 0;
}

int CServiceApp::ReadConfigFile(char *pFilename)
{
	FILE *fp;
	char tStr_Buf[100],*p,*t,tStr_Value[30];
	CString CStr_Value;

	fp=fopen(pFilename,"r");
	if(!fp)return 1;

	memset(tStr_Buf,0,100);
	while(fgets(tStr_Buf,80,fp)>0)	
	{
		p=tStr_Buf;
		strtok(p,"=");
		t=strtok(0,"/");
		if(t==NULL)continue;
		memset(tStr_Value,0,30);
		strcpy(tStr_Value,t);
		CStr_Value=tStr_Value;
		CStr_Value.TrimLeft();
		CStr_Value.TrimRight();
		if(CStr_Value.GetLength()==0)continue;

		if(strstr(tStr_Buf,"Database source"))
		{
				gStr_dsname=CStr_Value;
				goto LABLE_Continue;
		}
		if(strstr(tStr_Buf,"User Name"))
		{
				gStr_username=CStr_Value;
				goto LABLE_Continue;
		}
		if(strstr(tStr_Buf,"User Password"))
		{
				gStr_passwd=CStr_Value;
				goto LABLE_Continue;
		}
		if(strstr(tStr_Buf,"database type"))
		{
				gInt_dtype=atoi(CStr_Value);
				goto LABLE_Continue;
		}
LABLE_Continue:	
		memset(tStr_Buf,0,100);
	}
	fclose(fp);
	return 0;
}

⌨️ 快捷键说明

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