12.4. The Simplest Service
Listing 12.1 shows the simplest service possible. This service simply beeps. By default, it beeps every two seconds. Optionally, you can modify the beep interval with startup parameters. This service is complete in that it will appropriately respond to the Service Control Manager for every control signal possible. Because of that, this program can act as a good template for creating your own services. See Appendix A for compilation instructions.
Code Listing 12.1. A complete service that beeps at a fixed or user-controlled interval
// beepserv.cpp #include <windows.h> #include <stdio.h> #include <iostream.h> #include <stdlib.h> // Global variables // The name of the service char *SERVICE_NAME = "BeepService"; // Event ... |
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.