Question

the title is quite general but my doubt is specific. I have doubt regarding where to write the service logic code (in service control handler or in ServiceMain),as in whatever the functionality the service would perform . Is it in ServiceMain ? I have looked upon these topics on MSDN relate to service. But ,didn't help me http://msdn.microsoft.com/en-us/library/ms687414%28VS.85%29.aspx http://msdn.microsoft.com/en-us/library/ms685984%28v=vs.85%29.aspx

Basically, I want to start a socket listening on windows using a service. This listening socket logic code will be in service file because of I am going to use winexe utility to send this service from linux box to windows box. currently, winexe sends the winexesvc service file on windows. So, ultimately I am going to replace the existing winexesvc service so that it will perform listening on a particular port function when sent on windows. (Service skeleton would remain same but its task performing logic will change,right?). please tell if I am missing anything. Thanks in advance.

Was it helpful?

Solution

Service control handler should only, well, handle control messages that are sent to the service (the ones shown in the examples you linked are SERVICE_CONTROL_STOP and SERVICE_CONTROL_INTERROGATE). These control messages are sent to the service from the environment.

The logic of your service should be implemented in the ServiceMain function, when all required initialization is done. In the example at the URL in your post, the service logic code is put into the SvcInit function (which is probably not the most appropriate name for a function that implements logic of a service).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top