Search code examples
cvisual-studiowindows-servicesdaemon

Porting a UNIX daemon to a Windows Service


I wrote a UNIX daemon, in C, which I want to port to Windows. My target is Windows 10.

When I search on how to create a Windows service, I am met by an approach using .NET and C# which I both want to avoid at all cost.

How can I make a simple straightforward service in C, without kitchen sinks that Microsoft tries to unload on me? If I really have to, I would consider C++, but C# and .Net are simply taking it too far.

I'm fine with switching to a different compiler too, if this is easier outside of VisualStudio. (Currently I am using Visual Studio 2019, latest update.)

NOTE: My Linux daemon just has one dependency: libhidapi which is available for Windows.

UPDATE

No C++ templates available.

enter image description here


Solution

  • This comes down to creating two different applications (.exe)

    One to run the service using StartServiceCtrlDispatcher() where the dispatching function calls RegisterServiceCtrlHandlerEx() to register a controller.

    One to install the service using CreateService()

    It is possible to skip on the installer, and use the sc command line utility for that, which is part of the OS.

    See full example.