1 #ifndef NT_SERVC_INCLUDED 2 #define NT_SERVC_INCLUDED 3 4 /** 5 @file 6 7 @brief 8 Windows NT Service class library 9 10 Copyright Abandoned 1998 Irena Pancirov - Irnet Snc 11 This file is public domain and comes with NO WARRANTY of any kind 12 */ 13 14 // main application thread 15 typedef void (*THREAD_FC)(void *); 16 17 class NTService 18 { 19 public: 20 NTService(); 21 ~NTService(); 22 23 BOOL bOsNT; ///< true if OS is NT, false for Win95 24 //install optinos 25 DWORD dwDesiredAccess; 26 DWORD dwServiceType; 27 DWORD dwStartType; 28 DWORD dwErrorControl; 29 30 LPSTR szLoadOrderGroup; 31 LPDWORD lpdwTagID; 32 LPSTR szDependencies; 33 OSVERSIONINFO osVer; 34 35 // time-out (in milisec) 36 int nStartTimeOut; 37 int nStopTimeOut; 38 int nPauseTimeOut; 39 int nResumeTimeOut; 40 41 // 42 DWORD my_argc; 43 LPTSTR *my_argv; 44 HANDLE hShutdownEvent; 45 int nError; 46 DWORD dwState; 47 48 //init service entry point 49 long Init(LPCSTR szInternName,THREAD_FC ServiceThread); 50 51 //application shutdown event SetShutdownEvent(HANDLE hEvent)52 void SetShutdownEvent(HANDLE hEvent){ hShutdownEvent=hEvent; } 53 54 55 //service install / un-install 56 BOOL Install(int startType,LPCSTR szInternName,LPCSTR szDisplayName, 57 LPCSTR szFullPath, LPCSTR szAccountName=NULL, 58 LPCSTR szPassword=NULL); 59 BOOL SeekStatus(LPCSTR szInternName, int OperationType); 60 BOOL Remove(LPCSTR szInternName); 61 BOOL IsService(LPCSTR ServiceName); 62 BOOL got_service_option(char **argv, const char *service_option); 63 BOOL is_super_user(); 64 65 /* 66 SetRunning() is to be called by the application 67 when initialization completes and it can accept 68 stop request 69 */ 70 void SetRunning(void); 71 72 /** 73 Sets a timeout after which SCM will abort service startup if SetRunning() 74 was not called or the timeout was not extended with another call to 75 SetSlowStarting(). Should be called when static initialization completes, 76 and the variable initialization part begins 77 78 @arg timeout the timeout to pass to the SCM (in milliseconds) 79 */ 80 void SetSlowStarting(unsigned long timeout); 81 82 /* 83 Stop() is to be called by the application to stop 84 the service 85 */ 86 void Stop(void); 87 88 protected: 89 LPSTR ServiceName; 90 HANDLE hExitEvent; 91 SERVICE_STATUS_HANDLE hServiceStatusHandle; 92 BOOL bPause; 93 BOOL bRunning; 94 HANDLE hThreadHandle; 95 THREAD_FC fpServiceThread; 96 97 void PauseService(); 98 void ResumeService(); 99 void StopService(); 100 BOOL StartService(); 101 102 static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv); 103 static void WINAPI ServiceCtrlHandler (DWORD ctrlCode); 104 105 void Exit(DWORD error); 106 BOOL SetStatus (DWORD dwCurrentState,DWORD dwWin32ExitCode, 107 DWORD dwServiceSpecificExitCode, 108 DWORD dwCheckPoint,DWORD dwWaitHint); 109 110 }; 111 /* ------------------------- the end -------------------------------------- */ 112 113 #endif /* NT_SERVC_INCLUDED */ 114