1

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.

Akshay Patil
  • 954
  • 1
  • 12
  • 28

1 Answers1

1

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).

Roman Dmitrienko
  • 3,375
  • 3
  • 37
  • 48
  • yes,actually in winexe code , they have implemented the service logic code in serviceInitialization function where a new thread for server_loop is created. I still haven't tested the changed code for service ,still looks fine for what I was looking for. But , couldn't find ServiceMain function. Can ServiceMain function be called with different name ? – Akshay Patil Dec 25 '12 at 15:11
  • 1
    Yes, it can have any name. You can find it in the dispatch table which is passed to the `StartServiceCtrlDispatcher()` function. – Roman Dmitrienko Dec 26 '12 at 02:58