HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_NTService.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  *
7  * Authored by:
8  * Chris Thompson
9  * Side Effects Software Inc.
10  *
11  * NAME: UT_NTService.h (Utility Library, C++)
12  *
13  * COMMENTS: A C++ class to encapsulate most of the nasty
14  * work involved in writing Windows NT services.
15  * Derive from this to implement your own service.
16  *
17  */
18 
19 #ifndef __UT_NTService_h__
20 #define __UT_NTService_h__
21 
22 #include <windows.h>
23 
24 #include "UT_API.h"
25 #include "UT_Defines.h"
26 
27 #define UT_SERVICE_STOPPED 0
28 #define UT_SERVICE_RUNNING 1
29 #define UT_SERVICE_STARTING 2
30 
31 // Similar to WM_USER... use this as an offset for
32 // custom service control messages.
33 #define SERVICE_CONTROL_USER 128
34 
35 // For some reason this is not getting picked up
36 // from WinUser.h.
37 #define MB_SERVICE_NOTIFICATION 0x00200000L
38 
39 
41 {
42 public:
43  explicit UT_NTService(const char *serviceName);
44  virtual ~UT_NTService();
45 
46  virtual const char *getAboutString();
47  virtual const char *getVersionString();
48  virtual const char *getInstalledString();
49 
50  const char *getServiceExeName();
51  const char *getServiceUserName();
52 
53  UT_Bool isInstalled();
54  int isRunning();
55 
56  UT_Bool logEvent(WORD type,
57  DWORD id,
58  const char* string1 = UT_NULL,
59  const char* string2 = UT_NULL,
60  const char* string3 = UT_NULL);
61 
62  UT_Bool startService();
63 
64  void setStatus(DWORD state);
65 
67 
68  virtual void run();
69 
70  virtual UT_Bool onInit();
71  virtual void onStop();
72  virtual void onInterrogate();
73  virtual void onPause();
74  virtual void onContinue();
75  virtual void onShutdown();
76  virtual void onUserLogout();
77  virtual UT_Bool onUserControl(DWORD opcode);
78 
79  void debugMsg(const char* format, ...);
80  void userMsg(const char* format, ...);
81  void userDisplayLastError();
82  void userDisplayAdminError();
83 
84  static void WINAPI serviceMain(DWORD argc, LPTSTR* argv);
85  static void WINAPI handler(DWORD opcode);
86 
87  HINSTANCE getHInstance() { return myHInstance; };
88 
89  // We maintain the 'this' pointer so that serviceMain() and
90  // handler() can access the object.
91  static UT_NTService* myThis;
92 
93  char myServiceName[64];
94  SERVICE_STATUS_HANDLE myServiceStatus;
95  SERVICE_STATUS myStatus;
97 
98 protected:
99  void userMessageBox(LPCSTR msg, LPCSTR title, UINT type);
100 
101  static DWORD WINAPI msgBoxMain(LPVOID msgParam);
102  static BOOL WINAPI logoutHandler(DWORD ctrlType);
103  static BOOL CALLBACK EnumCloseProc(HWND hwnd, LPARAM lParam);
104 
105  HINSTANCE myHInstance;
107 };
108 
109 #endif // __UT_NTService_h__
int UT_Bool
Definition: UT_Defines.h:46
HINSTANCE myHInstance
Definition: UT_NTService.h:105
SERVICE_STATUS_HANDLE myServiceStatus
Definition: UT_NTService.h:94
#define UT_API
Definition: UT_API.h:12
UT_Bool myIsRunning
Definition: UT_NTService.h:96
SERVICE_STATUS myStatus
Definition: UT_NTService.h:95
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
HANDLE myEventSource
Definition: UT_NTService.h:106
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
#define UT_NULL
Definition: UT_Defines.h:26
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107