I've found a lot of questions on this topic which I will post links to. Unfortunately they all either didn't answer my question or they seem to but then led to code examples on msdn that didn't compile in Visual Studio.
I want to turn an exe compiled from Visual Studio in C++ into a service using the method mentioned in the top answer here but when I try to add the necessary serviceMain function which leads to all the other service functions that need to be added I end up trying to compile this file which doesn't compile. One of the many errors being that it complains about #include "sample.h"
because it's was never created despite the fact that the page notes that the compiler will generate that header file which VS doesn't do.
I just want to be able to take a self-made via VS exe made from a .cpp file and turn it ito a windows service without using an external program unless built into the OS such as sv.exe as mentioned in the link above with as little WINAPI as possible.
the code from that svc.cpp file produces the following errors with #include "smaple.h"
commented out.
argument of type "const char *" is incompatible with parameter of type "HMODULE"
identifier "SVC_ERROR" is undefined
'DWORD GetModuleFileNameW(HMODULE,LPWSTR,DWORD)': cannot convert argument 1 from 'const char [1]' to 'HMODULE'
'SVC_ERROR': undeclared identifier
Also when googling about the the const char errors I got led to this which didn't work even when changing the error code to active which is what it is for me. I got led to that because when I googled about the error I found another question in which the answer said that it depended on changing the build settings and when I googled about that I got led to the question I linked to directly above whose answer didn't work.
On a side note I can't believe how much harder it is (as well as how much more code is involved) to turn an executable program into a service is turning out to be when the only general difference is automatic vs manual execution.
Also if there is a way to do what I'm trying to do without using WINAPI nor an external program please let me know.
Update: I trying to imitate what programs such as AV programs do when they add themselves to the registry so that they autostart on boot.