For examples see
A basic Windows service in C++ (CppWindowsService) sample in C++ for Visual Studio 2008[
^] and
Simple Windows Service in C++[
^].
SERVICE_TABLE_ENTRY
and
SERVICE_STATUS
are defined in
Winsvc.h which is included by
Windows.h. So they should be known when compiling.
sc.exe is the service control manager command line application. It must be executed with sufficient privileges to create, start, and stop services. Creation must be done only once and is usually performed by an installation process (or manually for testing / non-public services using a command shell started as Administrator). When using a normal application that calls
ShellExecute
to execute
sc, that application has to be executed too with sufficient privileges.
Note also that you have to delete the service during development when a previous version has been already created. Not doing so will also result in Access denied errors.