12.7. Multiple Services in an Executable

It is possible, and sometimes useful, to put more than one service into a single executable. Generally you do this so that the separate service threads can communicate with one another through shared global variables. Because each of the services is a separate thread that shares the same data space, you can create global variables that are accessible by all of the services. The only requirement is that you use proper synchronization methods (see Chapter 7) to ensure valid access to the shared data.

When you create a multi-service EXE, you have to duplicate everything seen in Listing 12.1 except the main function. (See Figure 12.2.) During installation and when reporting status with SendStatusToSCM, you ...

Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.