Service programs are generally written as console applications. The entry point of a console application is the main function. The main function receives arguments from the ImagePath value from the registry key for the service.
When the SCM starts a service program, it waits for it to call the StartServiceCtrlDispatcher function. Use the following guidelines.
The StartServiceCtrlDispatcher function takes a SERVICE_TABLE_ENTRY structure for each service contained in the process. Each structure specifies the service name and the entry point for the service.
If StartServiceCtrlDispatcher succeeds, the calling thread does not return until all running services in the process have terminated. The SCM sends control requests to this thread through a named pipe. The thread acts as a control dispatcher, performing the following tasks:
For more information, see Writing a Service Program's main Function.