I use Viktor's 3.4 fork, but I just checked out the main stream 3.2 code and the file is contrib\hbwin\tests\service.prg there as well. I don't see testsvc.prg.
If you want to look at a real implementation have a look in contrib\hbnetio\utils\hbnetio, there you should see a file named _winsvc.prg, which is what hbnetio uses to install itself as a service. It's pretty close to what is in the service.prg mentioned so either would bring you up to speed. In the past I used my own C implementation to do this but I stopped using my code after discovering what came along natively with harbour.
Some service gotcha's:
1) You can use OutputDebugString() inside a service to write debug information to a debug viewer, but the debug viewer needs to be run as administrator, and it needs to be configured to capture Global Win32 messages in order to show the debug info.
2) Writing to the desktop is generally not good. It can be done, but personally I always avoid this. If you build with a GUI such as FWH innocuous things such as qout()/? which get redirected to a popup window will hang the service. FWH has an Alert() function (which conflicts with a function by the same name in harbour btw) that is called at times from within the FWH libraries, and that will hang the service. FWH assumes that it is always interacting with a user on the console, not as a headless service. I get around this by avoiding making FWH calls from within the service itself. In the case of the Alert() function I have yet another Alert() function within my code which I use to force the alert to a log instead of allowing it to try to open a window on the desktop.
I'm sure there are more that I am not remembering a the moment, but those are the big ones I recall.
Robb
↧