What Is the Service API?

The Service API consists of a set of functions and a couple of callback functions that must be supported. Together these functions allow an application to run independent of any logged-on user . This is not common to the entire Windows family of operating systems. For instance, the MSDE running on a Windows 9x machine is not available to users if no one is logged on to the workstation. This limited ability of Windows 9x workstations to make applications available to other users is probably reasonable for applications that make minimal demands and are run for a few desktops physically near each other. This breaks down, however, when the application to be served is used by a large number of users distributed over a wide area who are unlikely to be located near the application server. In this case, the ability to run independent of the currently logged-on user is essential.

At its heart, a service application supports at least three functions:

  • The main function This is just a standard main function with arguments like any console mode Win32 application. The main function must call certain functions in a timely manner.
  • The ServiceMain function This is the entry point for the service. The ServiceMain function must have the following prototype, though it can have a different name :
  •  VOIDWINAPIServiceMain(DWORDdwArgc,//Numberofarguments LPTSTR*lpszArgv//Arrayofargumentstringpointers); 

    One interesting feature of ServiceMain is that it takes the same arguments as a traditional C/C++ main function.

  • The control handler function This function receives requests for the service. The control handler function must have the following prototype, though it can have a different name:
  •  DWORDWINAPIHandlerEx(DWORDdwControl,//Requestedcontrolcode DWORDdwEventType,//Eventtype LPVOIDlpEventData,//Eventdata LPVOIDlpContext//User-definedcontextdata); 

Note that this function prototype has superseded the previous Handler prototype that expected only a single dwControl parameter. The old-style control handler function can still be specified for compatibility and is the only option for Windows NT 4 and earlier, but the new-style function is preferred for Windows 2000 service applications. Listing 3-1 will use the Handler function. Later examples in this book will use the new form of the control handler function. The HandlerEx function is primarily useful for services that need to manage multiple services from a single control handler or for a service that needs to react to device notifications.

Before we look at an example, we need to answer one question: if a service is running when no one is logged on, under whose authority does the service run?



Inside Server-Based Applications
Inside Server-Based Applications (DV-MPS General)
ISBN: 1572318171
EAN: 2147483647
Year: 1999
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net