Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: ntservice.h
  4. //
  5. // Module: Server Appliance
  6. //
  7. // Synopsis: Definitions for class CNTService
  8. //
  9. // Copyright (C) Microsoft Corporation. All rights reserved.
  10. //
  11. // Author: fengsun Created 3/11/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #ifndef NTSERVICE_H
  15. #define NTSERVICE_H
  16. #include <windows.h>
  17. #include <stdio.h>
  18. //+----------------------------------------------------------------------------
  19. //
  20. // class CNTService
  21. //
  22. // Synopsis: A class for writing NT service
  23. //
  24. // History: fengsun Created Header 3/10/99
  25. //
  26. //+----------------------------------------------------------------------------
  27. class CNTService
  28. {
  29. public:
  30. CNTService();
  31. ~CNTService();
  32. BOOL StartService(const TCHAR* pszServiceName, BOOL bRunAsService);
  33. static BOOL Install(const TCHAR* pszServiceName, const TCHAR* pszDisplayName,
  34. DWORD dwStartType = SERVICE_DEMAND_START,
  35. DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS);
  36. protected:
  37. void SetStatus(DWORD dwState);
  38. BOOL InitializeService();
  39. virtual void Run() {}; // No pure virtual function, which need purecall from CRT
  40. //
  41. // Whether the service can be loaded
  42. // called in ServiceMain , if return false, will stop the service
  43. //
  44. virtual BOOL CanLoad() {return TRUE;}
  45. virtual BOOL OnStop() {return TRUE;}
  46. void OnShutdown(){}; // change this to virtual, if overwriting is needed
  47. void OnControlMessage(DWORD /*dwOpcode*/){};
  48. // static member functions
  49. static void WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
  50. static void WINAPI Handler(DWORD dwOpcode);
  51. static void CreateConsoleThread(void);
  52. static DWORD __stdcall ConsoleThread(LPVOID);
  53. static BOOL IsInstalled(const TCHAR* pszServiceName);
  54. public:
  55. TCHAR m_szServiceName[32]; // The short name of the service
  56. SERVICE_STATUS_HANDLE m_hServiceStatus; // the handle to report status
  57. SERVICE_STATUS m_Status; // The service status structure
  58. BOOL m_bRunAsService; // whether running as a service or a console application
  59. public:
  60. static CNTService* m_pThis; // Point to the only instance
  61. };
  62. #endif // NTSERVICE_H