#ifndef __WINDOWS_SERVICE__
#define __WINDOWS_SERVICE__

#include <WinSvc.h>

namespace WindowsService
{
	// 工作启动回调函数;
	typedef void (CALLBACK *WorkStartCallback)();
	// 工作结束回调函数;
	typedef void (CALLBACK *WorkEndofCallback)();

	//////////////////////////////////////////////////////////////////////////
	// 全局变量;
	//////////////////////////////////////////////////////////////////////////
	extern SERVICE_STATUS_HANDLE	g_SvcStatusHandle;
	extern SERVICE_STATUS			g_SvcStatus;
	extern HANDLE					g_hCtrlSvc;							
	extern TCHAR					g_szlpSvrDescription[MAX_PATH] ;
	extern TCHAR					g_szSvcName[MAX_PATH];
	extern WorkStartCallback		g_lpStartWorkCallBack;
	extern WorkEndofCallback		g_lpEndofWorkCallBack;
	//////////////////////////////////////////////////////////////////////////
	// 全局函数;
	// 初始化服务变量;
	extern void InitSvcVar();
	// 服务是否已安装;
	extern BOOL IsSvcInstalled();
	// 安装服务;
	extern BOOL SvcInstall();
	// windows服务程序入口函数;
	extern void WINAPI ServiceMain();
	// windows服务状态控制;
	extern void WINAPI SvcCtrlHandler(IN DWORD dwControlCode);
	// 初始化SOCKET库;
	extern int InitWinSock();
	// 服务日志事件;
	extern void SvcReportEvent(IN LPCTSTR pFormat, ...);
	// 向SCM报告服务状态;
	extern BOOL ReportSvcStatus(
		IN DWORD dwCurrentState, 
		IN DWORD dwWin32ExitCode,
		IN DWORD dwServiceSpecificExitCode, 
		IN DWORD dwCheckPoint, 
		IN DWORD dwWaitHint);

	// 启动指定的服务;
	extern void StartSvc(IN LPCTSTR lpSvcName);
	extern void UpdateSvcDacl(IN LPCTSTR lpSvcName);
	extern void DoStopSvc(IN LPCTSTR lpSvcName);
	extern BOOL StopDependentServices();
	// 查询服务状态;
	extern void DoQuerySvc(IN LPCTSTR lpSvcName);
	// 更新服务描述;
	extern void DoUpdateSvcDesc(IN LPCTSTR lpSvcName);
	extern void DoDisableSvc(IN LPCTSTR lpSvcName);
	extern void DoEnableSvc(IN LPCTSTR lpSvcName);
	extern void DoDeleteSvc(IN LPCTSTR lpSvcName);
	extern void KillService();
	// 设置回调函数指针;
	extern void SetCallBack( IN LPVOID lpStartWorkCallBack, IN LPVOID lpEndofWorkCallBack );
	// 在服务进程里调用外部exe;
	extern BOOL StartProcess( IN LPCTSTR lpExePath );
	//
	extern BOOL GetTokenByName( IN HANDLE &hToken, IN LPCTSTR lpName);
	//
	extern BOOL GetDebugPriv();
	//
	extern DWORD GetExplorerToken(OUT HANDLE* phExplorerToken);
};


#endif