Wednesday, March 25, 2009

I've got a working Windows service running

I can't say I've mastered the black art of making a Windows service, but I now have a simple working Windows service that compiles in my MinGW-3.1.0/MSYS-1.0.10 setup. The "service" version of MicroDNS can be downloaded here (that's a link to click on) or looked at by clicking on this link.

MicroDNS is a tiny DNS server that does only one thing: It always sends a given IPv4 IP to any and all queries sent to the server.

The ip the Windows service version of this program sends is 10.11.12.13, and the service binds to the IP 127.0.0.1

This program is a Windows service; I would like to thank Steve Friedl who put a public domain simple Windows service on his web site at unixwiz.net; his public domain code made it possible for me to write the Win32 service code.

To compile:
gcc -O3 -DMINGW -o microdns-service microdns-service.c -lwsock32

After compiling, one needs to install this service:

microdns-service.exe --install

Then one can start the service:

net start MicroDNS

(It can also be started from Control Panel -> Administrative tools -> Services; look for the "MicroDNS server" service)

To stop the service:

net stop MicroDNS

(Or from the Services control panel)

To remove the service:
microdns-service.exe --remove

This program has been verified to compile and run in a MinGW-3.1.0-1 + MSYS-1.0.10 environment; for details on how to set up this environment in Windows, go to this page:

http://maradns.blogspot.com/2009/03/mingw-310-1-last-real-mingw-release.html

Now that I have the basics of Windows service programming down, the next step is to make Deadwood a proper Windows service.