1

I have a Windows Service written in C++ where I don't have the control over the source code, i.e. I cannot rewrite it. I also don't have the possibility to install it as a service and control it via ServiceController.

So the question is if it's possible to use DllImport and from C# "emulate" the service controller to initialize the service and run OnStart and OnStop from there? I've tried to find the entry point by using PEview and other tools, but can't find anything. When running it in C# and looking for "main" I get "System.EntryPointNotFoundException: 'Unable to find an entry point named 'main' in DLL ... "

When dumping /exports with dumpbin.exe there are no exports at all.

Is there a "standard" way to manage a windows service like the Service Controller do it?

  • Here's the [first method (`StartServiceCtrlDispatcher`)](https://learn.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-startservicectrldispatchera) that the C++ application should be calling to start being recognised as a service. You would have to detour several windows API calls before allowing the service code to run and trying to do that from a managed language would be... challenging. – Damien_The_Unbeliever Mar 22 '21 at 08:18
  • @Damien_The_Unbeliever You're probably right. My hope was to find something like a windows service wrapper to use, but usually the problem is the opposite - wrapping it like a service. – Kristian Falk Mar 30 '21 at 12:31

0 Answers0