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