www.pudn.com > insoructions-nitm.zip > ServiceApp.h, change:2004-04-14,size:2311b


// ServiceApp.h: interface for the CServiceApp class. 
// 
/******************************************************************** 
	created:	2004/12/03 
	author:		Robin Liu 
	email:		robinliu@tsinghua.org.cn 
	purpose:	Create a NT service framework. 
*********************************************************************/ 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_SERVICEAPP_H__9B9762F4_6EB1_422A_87D0_5995275C76FF__INCLUDED_) 
#define AFX_SERVICEAPP_H__9B9762F4_6EB1_422A_87D0_5995275C76FF__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
// #include "Windows.h" 
 
typedef DWORD SERVICE_CTRL_CODE; 
 
class CServiceApp 
{ 
	DECLARE_SERVICE(CServiceApp) 
public: 
	CServiceApp(); 
	virtual ~CServiceApp(); 
	void Init(); 
	static void PreInitialise(HINSTANCE hInstance,  
			HINSTANCE hPrevInstance, 
			LPSTR lpCmdLine, 
			int nCmdShow); 
	static int Main(HINSTANCE hInstance, LPSTR lpCmdLine); 
	BOOL IsInstalled(); 
	BOOL Install(); 
    BOOL Uninstall(); 
	void Start(); 
	void ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv); 
	void Handler(DWORD dwOpcode); 
	void LogEvent(LPCTSTR pFormat, ...); 
	void SetServiceStatus(DWORD dwState); 
	void Run(); 
	void Continue(); 
	void Pause(); 
	void Shutdown(); 
	void Stop(); 
	virtual void Help(); 
 
protected: 
	virtual BOOL OnStart(); 
	virtual BOOL OnRunning(); 
	virtual BOOL OnContinue(); 
	virtual BOOL OnPause(); 
	virtual BOOL OnShutdown(); 
	virtual BOOL OnStop(); 
	void ShowHelpMessage(); 
 
protected: 
	TCHAR m_szServiceName[256]; 
	SERVICE_STATUS_HANDLE m_hServiceStatus; 
    SERVICE_STATUS m_status; 
	DWORD dwThreadID; 
 
protected: 
	virtual SERVICE_CTRL_CODE ProcessArguments(); 
	static SERVICE_CTRL_CODE DefProcessArguments(LPSTR lpCmdLine); 
	BOOL WaitForServiceState(SC_HANDLE hService, 
		SERVICE_CTRL_CODE dwDesiredState,  
		SERVICE_STATUS* lpServiceStatus,  
		DWORD dwMilliseconds); 
 
private: 
	static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv); 
	static void WINAPI _Handler(DWORD dwOpcode); 
 
private: 
	static HINSTANCE m_hInstance; 
    static HINSTANCE m_hPrevInstance; 
    static LPSTR     m_lpCmdLine; 
	static int       m_nCmdShow; 
}; 
 
#endif // !defined(AFX_SERVICEAPP_H__9B9762F4_6EB1_422A_87D0_5995275C76FF__INCLUDED_)