home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / winwrap.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  10KB  |  196 lines

  1. // --winwrap.h------------------------------------------------------------------
  2. //
  3. // Header file for Windows NT service (Windows application) shell for EDK
  4. // applications.
  5. // 
  6. // Copyright (C) Microsoft Corp., 1986-1996.  All Rights Reserved.
  7. // -----------------------------------------------------------------------------
  8.  
  9. #ifndef _WINWRAP_H
  10. #define _WINWRAP_H
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif // __cplusplus
  15.  
  16. #define MAX_SERVICE_NAME_LENGTH 256
  17.  
  18. //$--EDK_Service_Control_T---------------------------------------------------
  19. //  Service control instructions returned by HrServiceWaitForControl().
  20. // --------------------------------------------------------------------------
  21. typedef enum _EDKServiceControl_T
  22. {
  23.     EDK_SC_NONE = 0,    // no change
  24.     EDK_SC_PAUSE,       // pause the service
  25.     EDK_SC_CONTINUE,    // continue the service
  26.     EDK_SC_STOP,        // stop the service
  27.     EDK_SC_LAST         // all values are less than this
  28. } EDK_SERVICE_CONTROL_T;
  29.  
  30. //$--FIsService-----------------------------------------------------------------
  31. //  Returns TRUE if the application is running as an NT service.
  32. // -----------------------------------------------------------------------------
  33. BOOL FIsService(                        // RETURNS: TRUE if service
  34.     IN VOID);                           // no arguments
  35.  
  36. //$--GetServiceStopEvent-------------------------------------------------------
  37. //  Returns the handle for the service stop event.
  38. // -----------------------------------------------------------------------------
  39. HANDLE GetServiceStopEvent(            // RETURNS: handle to stop event
  40.     VOID);                              // no arguments
  41.  
  42. //$--GetServiceInstance--------------------------------------------------------
  43. //  Returns the handle for the service instance.
  44. // -----------------------------------------------------------------------------
  45. HANDLE GetServiceInstance(             // RETURNS: handle to service instance
  46.     VOID);                              // no arguments
  47.  
  48. //$--HServiceCreateThread-----------------------------------------------------------
  49. //  Create a wrapped thread.
  50. // -----------------------------------------------------------------------------
  51. HANDLE HServiceCreateThread(                            // RETURNS: handle
  52.     IN  LPLONG lplStartThreads,                     // number of running threads
  53.     IN  LPLONG lplStopThreads,                      // number of stopped threads
  54.     IN  LPSECURITY_ATTRIBUTES lpThreadAttributes,   // thread attributes
  55.     IN  DWORD dwStackSize,                          // stack size
  56.     IN  LPTHREAD_START_ROUTINE lpStartAddress,      // start address
  57.     IN  LPVOID lpParameter,                         // parameter
  58.     IN  DWORD dwCreationFlags,                      // creation flags
  59.     OUT LPDWORD lpThreadId);                        // thread ID
  60.  
  61. //$--SetServiceExitCode---------------------------------------------------------
  62. //  This function is called by the application to set the service exit code.
  63. //
  64. //  dwWin32ExitCode
  65. //
  66. //      - specifies a Win32 error code that the service uses to
  67. //        report an error that occurs when it is starting or
  68. //        stopping. To return an error code specific to the service,
  69. //        the service must set this value to
  70. //        ERROR_SERVICE_SPECIFIC_ERROR to indicate that the
  71. //        dwServiceSpecificExitCode member contains the error code.
  72. //        The service should set this value to NO_ERROR when it is
  73. //        running and on normal termination. 
  74. //
  75. //  dwServiceSpecificExitCode
  76. //
  77. //      - specifies a service specific error code that the
  78. //        service returns when an error occurs while the service is
  79. //        starting or stopping. This value is ignored unless the
  80. //        dwWin32ExitCode member is set to ERROR_SERVICE_SPECIFIC_ERROR. 
  81. //      
  82. // -----------------------------------------------------------------------------
  83. VOID SetServiceExitCode(
  84.     IN DWORD dwWin32ExitCode,           // Win32 exit code
  85.     IN DWORD dwServiceSpecificExitCode);// service specific exit code
  86.  
  87. //$--HrServiceConfirmStop----------------------------------------------------
  88. //  This function is called by the application to indicate that it has stopped.
  89. // -----------------------------------------------------------------------------
  90. HRESULT HrServiceConfirmStop(        // RETURNS: return code
  91.     VOID);                              // no arguments
  92.  
  93. //$--HrServiceGetName--------------------------------------------------------
  94. //  The HrServiceGetName function can be used by any thread to get the
  95. //  service name after the service has been started. lpszName must point to a
  96. //  block of memory at least MAX_SERVICE_NAME_LENGTH+1 bytes in length.
  97. // -----------------------------------------------------------------------------
  98. HRESULT HrServiceGetName(            // RETURNS: return code
  99.     OUT LPSTR lpszName);                // pointer to service name buffer
  100.  
  101. //$--HrServiceGetArgv--------------------------------------------------------
  102. //  The HrServiceGetArgv function can be used by any thread to get the
  103. //  service argv[] after the service has been started.
  104. // -----------------------------------------------------------------------------
  105. HRESULT HrServiceGetArgv(            // RETURNS: return code
  106.     OUT DWORD  *lpdwArgc,               // pointer to argc address variable
  107.     OUT LPSTR **lppszArgv);             // pointer to argv[] address variable
  108.  
  109. //$--FServiceReportStatus-------------------------------------------------------
  110. //  This function is called by the private _ServiceMain() and
  111. //  ServCtrlHandler() functions to update the service's status
  112. //  to the service control manager.
  113. // -----------------------------------------------------------------------------
  114. BOOL FServiceReportStatus(              // RETURNS: TRUE if successful
  115.     IN DWORD dwCurrentState,            // current state of service
  116.     IN DWORD dwWin32ExitCode,           // service Win32 exit code
  117.     IN DWORD dwServiceSpecificExitCode, // service specific exit code
  118.     IN DWORD dwCheckPoint,              // check point number
  119.     IN DWORD dwWaitHint);               // time to wait
  120.  
  121. //$--ServiceStop-------------------------------------------------------------
  122. //  This function can be used by any thread to stop the service.
  123. // -----------------------------------------------------------------------------
  124. VOID ServiceStop(                    // RETURNS: nothing
  125.     VOID);                              // no argument
  126.  
  127.  
  128. //$--HrServiceWaitForControl----------------------------------------------------
  129. //  The HrServiceWaitForControl function can be used by any thread to get or
  130. //  wait for service control after the service has been started.
  131. // -----------------------------------------------------------------------------
  132. HRESULT HrServiceWaitForControl(        // RETURNS: return code
  133.     IN DWORD dwTimeout,                 // time-out interval in milliseconds
  134.     OUT EDK_SERVICE_CONTROL_T *pedksc); // pointer to service name buffer
  135.  
  136. //$--HrServiceWaitForContinue---------------------------------------------------
  137. //  The HrServiceWaitForContinue function can be used by any thread to get or
  138. //  wait for service control after the service has been started.
  139. // -----------------------------------------------------------------------------
  140. HRESULT HrServiceWaitForContinue(       // RETURNS: return code
  141.     IN DWORD dwTimeout,                 // time-out interval in milliseconds
  142.     OUT EDK_SERVICE_CONTROL_T *pedksc); // pointer to service name buffer
  143.  
  144. //$--HrServiceWaitForStop-------------------------------------------------------
  145. //  The HrServiceWaitForStop function can be used by any thread to get or
  146. //  wait for service control after the service has been started.
  147. // -----------------------------------------------------------------------------
  148. HRESULT HrServiceWaitForStop(           // RETURNS: return code
  149.     IN DWORD dwTimeout,                 // time-out interval in milliseconds
  150.     OUT EDK_SERVICE_CONTROL_T *pedksc); // pointer to service name buffer
  151.  
  152. //$--HrServiceProcessControl---------------------------------------------------
  153. //  Check for service control
  154. // -----------------------------------------------------------------------------
  155. HRESULT HrServiceProcessControl(       // RETURNS: return code
  156.     VOID);                              // no arguments
  157.  
  158. //
  159. //  The following service functions and extern variables are defined by the
  160. //  application writer.
  161. //
  162.  
  163. //$--HrServiceStartup---------------------------------------------------------
  164. //  This function is called at startup to initialize the NT service.
  165. //------------------------------------------------------------------------------
  166. HRESULT HrServiceStartup(             // RETURNS: return code
  167.     IN HINSTANCE hInstance,             // handle of current instance
  168.     IN HINSTANCE hPrevInstance,         // handle of previous instance
  169.     IN HWND hwndMainWindow,             // handle to main window
  170.     IN LPSTR pszCmdLine);               // pointer to command line
  171.  
  172. //$--ServiceMain--------------------------------------------------------------
  173. //  This function is given its own thread to execute.
  174. //------------------------------------------------------------------------------
  175. void ServiceMain(                     // RETURNS: nothing
  176.     IN HANDLE hShutdownEvent);          // Handle to Shutdown event object
  177.  
  178. //$--HrServiceShutdown--------------------------------------------------------
  179. //  This function is called when the user wants to shutdown.
  180. //------------------------------------------------------------------------------
  181. HRESULT HrServiceShutdown(            // RETURNS: return value for WinMain
  182.     VOID);                              // No arguments
  183.  
  184. //------------------------------------------------------------------------------
  185.  
  186. extern CHAR szAppName[];               // WNDCLASS class name
  187. extern CHAR szWindowTitle[];           // Application window title
  188.  
  189. //------------------------------------------------------------------------------
  190.  
  191. #ifdef __cplusplus
  192. }
  193. #endif // __cplusplus
  194.  
  195. #endif
  196.