00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _WINSERVICE_
00014 #define _WINSERVICE_
00015
00016 #include <windows.h>
00017 #include <string>
00018
00019 #define SERVICE_CONTROL_USER 128
00020
00021 typedef enum {
00022 STATUS,
00023 START,
00024 STOP,
00025 INSTALL,
00026 UNINSTALL,
00027 SERVICE,
00028 RUN,
00029 HELP,
00030 INVALID
00031 } EServiceState;
00032
00033 class TWinService
00034 {
00035 public:
00036 std::string ServiceDir;
00037 TWinService(const char* serviceName, const char* dispName,
00038 DWORD deviceType=SERVICE_DEMAND_START,
00039 char* dependencies=NULL, char* descr=NULL);
00040 static void WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
00041 static void WINAPI Handler(DWORD dwOpcode);
00042 void LogEvent(WORD wType, DWORD dwID, const char* pszS1 = NULL,
00043 const char* pszS2 = NULL, const char* pszS3 = NULL);
00044 bool IsInstalled();
00045 bool IsInstalled(const char *name);
00046 bool Install();
00047 bool Uninstall();
00048 bool StartService();
00049 bool RunService();
00050 bool StopService();
00051 void SetStatus(DWORD dwState);
00052 bool Initialize();
00053 void showStatus();
00054 bool verifyPort();
00055 int getStatus();
00056 bool isRunning(const char * name);
00057 bool isRunning();
00058
00059 virtual void Run();
00060 virtual bool OnInit();
00061 virtual void OnStop();
00062 virtual void OnInterrogate();
00063 virtual void OnPause();
00064 virtual void OnContinue();
00065 virtual void OnShutdown();
00066 virtual bool OnUserControl(DWORD dwOpcode);
00067
00068 ~TWinService(void);
00069
00070 protected:
00071 SERVICE_STATUS Status;
00072 SERVICE_STATUS_HANDLE hServiceStatus;
00073 BOOL IsRunning;
00074
00075 char ServiceName[64];
00076 int MajorVersion;
00077 int MinorVersion;
00078 DWORD ServiceType;
00079 char* Dependencies;
00080 char* DisplayName;
00081 char* descr;
00082 static TWinService* ServicePtr;
00083 HANDLE EventSource;
00084 };
00085 #endif
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096