Writing Windows ServicesOverview
Windows services run under the control of a Service Control Manager (SCM). Converting a console application, such as serverNP or serverSK, to a Windows service requires three major steps to place the program under the SCM.
1. | Create a new main() entry point that registers the service with the SCM, supplying the logical service entry points and names. |
2. | Convert the old main() entry point function to ServiceMain(), which registers a service control handler and informs the SCM of its status. The remaining code is essentially that of the existing program, although event logging commands can be added. The name ServiceMain() is a placeholder for the name of a logical service, and there can be one or more logical services. |
3. | Write the service control handler function to respond to commands from the SCM. |
As these three steps are described, there will be several references to creating, starting, and controlling services. The specifics are described in later sections, and Figure 13-1, later in the chapter, illustrates the component interactions.
Figure 13-1. Controlling Windows Services Through the SCM
