-/* A function pointer for dynamic linking tricks */
-SETSERVDESC ChangeServiceConf;
-
-LPCSTR RetrieveLastError()
-{
- static char err[100];
- DWORD LastError = GetLastError();
- if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, LastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)err, sizeof(err), 0) == 0)
- snprintf(err, sizeof(err), "Error code: %d", LastError);
- SetLastError(ERROR_SUCCESS);
- return err;
-}
-
-/* Returns true if this program is running as a service, false if it is running interactive */
-bool IsAService()
-{
- USEROBJECTFLAGS uoflags;
- HWINSTA winstation = GetProcessWindowStation();
- if (GetUserObjectInformation(winstation, UOI_FLAGS, &uoflags, sizeof(uoflags), NULL))
- return ((uoflags.dwFlags & WSF_VISIBLE) == 0);
- else
- return false;
-}
-
-/* Kills the service by setting an event which the other thread picks up and exits */
-void KillService()
-{
- SetEvent(hThreadEvent);
- Sleep(2000);
- SetEvent(killServiceEvent);
-}