1. Windows services
- Posted by daduko Aug 07, 2010
- 1084 views
Hello,
I need to port my program (reading from serial port) to run as Windows Service program. In the archive I've found Windows service library, but I need some another sample with EU code to understand it. It can be just beeping every second or so.
Thank you
Vlado
2. Re: Windows services
- Posted by m_sabal Aug 11, 2010
- 1048 views
The general flow of a service program is this: 1) Register the DispatchTable, which contains a callback to the service start routine. 2) In the service start routine: 2a) Register the callback to the service handler routine. 2b) Have a payload loop that does whatever the service needs to do. Usually, this will have a call to sleep() for some seconds since you're usually checking for a condition periodically to take action on.
The winsvctest.exw program included in the zip file you downloaded is as basic as it gets. I recommend you use that file as a template for whatever project you're working on. The text "MyService" on line 96 is irrelevant and can stay as it is. The service name "MyService" in line 53 should be changed to the name you plan to use when you install the service (sc create...). The payload is in lines 65-79. You'll customize this loop for your own needs. If you'd rather not make a call to GetServiceStatus in each loop iteration, then make doneFlag a file-level variable and set it to 1 between lines 34 and 35 in myServiceHandler.