From 12450e2f0e80c730d4946d3d8070a50020d8f028 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 5 Dec 2020 23:20:40 -0500 Subject: [PATCH] Formatting changes --- ServiceExample.sln | 44 +-- ServiceExample/Main.cpp | 296 +++++++++--------- ServiceExample/Models.h | 68 ++--- ServiceExample/ServiceControlHandler.hpp | 164 +++++----- ServiceExample/ServiceEntryPoint.hpp | 362 +++++++++++------------ ServiceExample/ServiceExample.vcxproj | 184 ++++++------ 6 files changed, 559 insertions(+), 559 deletions(-) diff --git a/ServiceExample.sln b/ServiceExample.sln index 38dd6ee..639ed71 100644 --- a/ServiceExample.sln +++ b/ServiceExample.sln @@ -1,22 +1,22 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServiceExample", "ServiceExample\ServiceExample.vcxproj", "{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Debug|Win32.ActiveCfg = Debug|Win32 - {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Debug|Win32.Build.0 = Debug|Win32 - {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.ActiveCfg = Release|Win32 - {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServiceExample", "ServiceExample\ServiceExample.vcxproj", "{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Debug|Win32.ActiveCfg = Debug|Win32 + {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Debug|Win32.Build.0 = Debug|Win32 + {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.ActiveCfg = Release|Win32 + {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ServiceExample/Main.cpp b/ServiceExample/Main.cpp index 45dd3d1..5f51261 100644 --- a/ServiceExample/Main.cpp +++ b/ServiceExample/Main.cpp @@ -1,148 +1,148 @@ -#include -#include -#include -#include - -#include -#include -#include - -#pragma comment(lib, "advapi32.lib") -#pragma comment(lib, "kernel32.lib") - -#include "Models.h" -#include "ServiceEntryPoint.hpp" - - -template -VOID ServiceInstall(void); -template -VOID ServiceReportEvent(LPTSTR); - -std::shared_ptr> service_info(new models::ServiceInfo<>(L"Service Example")); - - -#undef main - -int _tmain(int argc, TCHAR *argv[]) -{ - std::cout << "ServiceExample\n"; - - if (lstrcmpi(argv[1], TEXT("install")) == 0) - { - ServiceInstall(); - - return -1; - } - - - SERVICE_TABLE_ENTRY SERVICETABLE[] = - { - { service_info->service_name, - (LPSERVICE_MAIN_FUNCTION) - service::ServiceEntryPoint::service_main_start }, - { nullptr, nullptr }, - }; - - if (!StartServiceCtrlDispatcher(SERVICETABLE)) - { - auto func = reinterpret_cast(TEXT("StartServiceCtrlDispatcher")); - ServiceReportEvent(func); - } - - - return 0; -} - - - -template -VOID ServiceInstall() -{ - Char buffer[MAX_PATH]; - - if (!GetModuleFileName(nullptr, buffer, MAX_PATH)) - { - std::cout << "Cannot install service " << GetLastError() << "\n"; - - return; - } - - // Get a handle to the SCM database. - - Handle schSCManager = OpenSCManager( - nullptr, // local computer - nullptr, // ServicesActive database - SC_MANAGER_ALL_ACCESS); // full access rights - - if (nullptr == schSCManager) - { - std::cout << "OpenSCManager failed " << GetLastError() << "\n"; - - return; - } - - // Create the service - - Handle schService = CreateService( - schSCManager, // SCM database - service_info->service_name, // name of service - service_info->service_name, // service name to display - SERVICE_ALL_ACCESS, // desired access - SERVICE_WIN32_OWN_PROCESS, // service type - SERVICE_DEMAND_START, // start type - SERVICE_ERROR_NORMAL, // error control type - buffer, // path to service's binary - nullptr, // no load ordering group - nullptr, // no tag identifier - nullptr, // no dependencies - nullptr, // LocalSystem account - nullptr); // no password - - if (schService == nullptr) - { - std::cout << "CreateService failed " << GetLastError() << "\n"; - - CloseServiceHandle(schSCManager); - return; - } - else - { - std::cout << "Service installed successfully\n"; - } - - CloseServiceHandle(schService); - CloseServiceHandle(schSCManager); -} - -template -VOID ServiceReportEvent(LPTSTR szFunction) -{ - CTStr lpszStrings[2]; - Char Buffer[80]; - - Handle hEventSource = RegisterEventSource(nullptr, service_info->service_name); - - if (nullptr != hEventSource) - { - StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError()); - - lpszStrings[0] = service_info->service_name; - lpszStrings[1] = Buffer; - - ReportEvent(hEventSource, // event log handle - EVENTLOG_ERROR_TYPE, // event type - 0, // event category - SERVICE_ERROR_NORMAL, // event identifier - nullptr, // no security identifier - 2, // size of lpszStrings array - 0, // no binary data - lpszStrings, // array of strings - nullptr); // no binary data - - DeregisterEventSource(hEventSource); - } -} - +#include +#include +#include +#include + +#include +#include +#include + +#pragma comment(lib, "advapi32.lib") +#pragma comment(lib, "kernel32.lib") + +#include "Models.h" +#include "ServiceEntryPoint.hpp" + + +template +VOID ServiceInstall(void); +template +VOID ServiceReportEvent(LPTSTR); + +std::shared_ptr> service_info(new models::ServiceInfo<>(L"Service Example")); + + +#undef main + +int _tmain(int argc, TCHAR *argv[]) +{ + std::cout << "ServiceExample\n"; + + if (lstrcmpi(argv[1], TEXT("install")) == 0) + { + ServiceInstall(); + + return -1; + } + + + SERVICE_TABLE_ENTRY SERVICETABLE[] = + { + { service_info->service_name, + (LPSERVICE_MAIN_FUNCTION) + service::ServiceEntryPoint::service_main_start }, + { nullptr, nullptr }, + }; + + if (!StartServiceCtrlDispatcher(SERVICETABLE)) + { + auto func = reinterpret_cast(TEXT("StartServiceCtrlDispatcher")); + ServiceReportEvent(func); + } + + + return 0; +} + + + +template +VOID ServiceInstall() +{ + Char buffer[MAX_PATH]; + + if (!GetModuleFileName(nullptr, buffer, MAX_PATH)) + { + std::cout << "Cannot install service " << GetLastError() << "\n"; + + return; + } + + // Get a handle to the SCM database. + + Handle schSCManager = OpenSCManager( + nullptr, // local computer + nullptr, // ServicesActive database + SC_MANAGER_ALL_ACCESS); // full access rights + + if (nullptr == schSCManager) + { + std::cout << "OpenSCManager failed " << GetLastError() << "\n"; + + return; + } + + // Create the service + + Handle schService = CreateService( + schSCManager, // SCM database + service_info->service_name, // name of service + service_info->service_name, // service name to display + SERVICE_ALL_ACCESS, // desired access + SERVICE_WIN32_OWN_PROCESS, // service type + SERVICE_DEMAND_START, // start type + SERVICE_ERROR_NORMAL, // error control type + buffer, // path to service's binary + nullptr, // no load ordering group + nullptr, // no tag identifier + nullptr, // no dependencies + nullptr, // LocalSystem account + nullptr); // no password + + if (schService == nullptr) + { + std::cout << "CreateService failed " << GetLastError() << "\n"; + + CloseServiceHandle(schSCManager); + return; + } + else + { + std::cout << "Service installed successfully\n"; + } + + CloseServiceHandle(schService); + CloseServiceHandle(schSCManager); +} + +template +VOID ServiceReportEvent(LPTSTR szFunction) +{ + CTStr lpszStrings[2]; + Char Buffer[80]; + + Handle hEventSource = RegisterEventSource(nullptr, service_info->service_name); + + if (nullptr != hEventSource) + { + StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError()); + + lpszStrings[0] = service_info->service_name; + lpszStrings[1] = Buffer; + + ReportEvent(hEventSource, // event log handle + EVENTLOG_ERROR_TYPE, // event type + 0, // event category + SERVICE_ERROR_NORMAL, // event identifier + nullptr, // no security identifier + 2, // size of lpszStrings array + 0, // no binary data + lpszStrings, // array of strings + nullptr); // no binary data + + DeregisterEventSource(hEventSource); + } +} + diff --git a/ServiceExample/Models.h b/ServiceExample/Models.h index 37e95db..a24553b 100644 --- a/ServiceExample/Models.h +++ b/ServiceExample/Models.h @@ -1,34 +1,34 @@ -#ifndef MODELS_H_ -#define MODELS_H_ - -#include - - -namespace models -{ - template - class ServiceInfo - { - public: - ServiceInfo() - { - service_stop_event = INVALID_HANDLE_VALUE; - } - ServiceInfo(std::wstring &&name) : - service_name(const_cast(name.c_str())) - { - service_stop_event = INVALID_HANDLE_VALUE; - } - - wchar_t *service_name; - Status service_status; - StatusHandle service_handle; - Handle service_stop_event; - }; -} - -#endif \ No newline at end of file +#ifndef MODELS_H_ +#define MODELS_H_ + +#include + + +namespace models +{ + template + class ServiceInfo + { + public: + ServiceInfo() + { + service_stop_event = INVALID_HANDLE_VALUE; + } + ServiceInfo(std::wstring &&name) : + service_name(const_cast(name.c_str())) + { + service_stop_event = INVALID_HANDLE_VALUE; + } + + wchar_t *service_name; + Status service_status; + StatusHandle service_handle; + Handle service_stop_event; + }; +} + +#endif diff --git a/ServiceExample/ServiceControlHandler.hpp b/ServiceExample/ServiceControlHandler.hpp index 4597c54..8a35a4e 100644 --- a/ServiceExample/ServiceControlHandler.hpp +++ b/ServiceExample/ServiceControlHandler.hpp @@ -1,82 +1,82 @@ -#ifndef SERVICECONTROLHANDLER_H_ -#define SERVICECONTROLHANDLER_H_ - -#include - -#include -#include -#include - -#include "Models.h" - -namespace service -{ - class ServiceControlHandler - { - public: - template, - typename Ptr = std::shared_ptr> - static VOID WINAPI ServiceCtrlHandler(D ctrlCode) - { - extern Ptr service_info; - - switch (ctrlCode) - { - case SERVICE_CONTROL_STOP: - ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); - - SetEvent(service_info->service_stop_event); - ReportServiceStatus(service_info->service_status.dwCurrentState, NO_ERROR, 0); - - return; - case SERVICE_CONTROL_INTERROGATE: - break; - default: - break; - } - } - - - template, - typename Ptr = std::shared_ptr> - static VOID ReportServiceStatus(D dwCurrentState, - D dwWin32ExitCode, - D dwWaitHint) - { - extern Ptr service_info; - - static D dwCheckPoint = 1; - - service_info->service_status.dwCurrentState = dwCurrentState; - service_info->service_status.dwWin32ExitCode = dwWin32ExitCode; - service_info->service_status.dwWaitHint = dwWaitHint; - - if (dwCurrentState == SERVICE_START_PENDING) - { - service_info->service_status.dwControlsAccepted = 0; - } - else - { - service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; - } - - if ((dwCurrentState == SERVICE_RUNNING) || - (dwCurrentState == SERVICE_STOPPED)) - { - service_info->service_status.dwCheckPoint = 0; - } - else - { - service_info->service_status.dwCheckPoint = dwCheckPoint++; - } - - SetServiceStatus(service_info->service_handle, &service_info->service_status); - } - - private: - }; -} - -#endif \ No newline at end of file +#ifndef SERVICECONTROLHANDLER_H_ +#define SERVICECONTROLHANDLER_H_ + +#include + +#include +#include +#include + +#include "Models.h" + +namespace service +{ + class ServiceControlHandler + { + public: + template, + typename Ptr = std::shared_ptr> + static VOID WINAPI ServiceCtrlHandler(D ctrlCode) + { + extern Ptr service_info; + + switch (ctrlCode) + { + case SERVICE_CONTROL_STOP: + ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); + + SetEvent(service_info->service_stop_event); + ReportServiceStatus(service_info->service_status.dwCurrentState, NO_ERROR, 0); + + return; + case SERVICE_CONTROL_INTERROGATE: + break; + default: + break; + } + } + + + template, + typename Ptr = std::shared_ptr> + static VOID ReportServiceStatus(D dwCurrentState, + D dwWin32ExitCode, + D dwWaitHint) + { + extern Ptr service_info; + + static D dwCheckPoint = 1; + + service_info->service_status.dwCurrentState = dwCurrentState; + service_info->service_status.dwWin32ExitCode = dwWin32ExitCode; + service_info->service_status.dwWaitHint = dwWaitHint; + + if (dwCurrentState == SERVICE_START_PENDING) + { + service_info->service_status.dwControlsAccepted = 0; + } + else + { + service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; + } + + if ((dwCurrentState == SERVICE_RUNNING) || + (dwCurrentState == SERVICE_STOPPED)) + { + service_info->service_status.dwCheckPoint = 0; + } + else + { + service_info->service_status.dwCheckPoint = dwCheckPoint++; + } + + SetServiceStatus(service_info->service_handle, &service_info->service_status); + } + + private: + }; +} + +#endif diff --git a/ServiceExample/ServiceEntryPoint.hpp b/ServiceExample/ServiceEntryPoint.hpp index 8aaacd4..eedcc42 100644 --- a/ServiceExample/ServiceEntryPoint.hpp +++ b/ServiceExample/ServiceEntryPoint.hpp @@ -1,181 +1,181 @@ -#ifndef SERVICEENTRYPOINT_H_ -#define SERVICEENTRYPOINT_H_ - -#include -#include - -#include -#include -#include - -#include "Models.h" -#include "ServiceControlHandler.hpp" - -namespace service -{ - class ServiceEntryPoint - { - public: - ServiceEntryPoint() = default; - - template, - typename Ptr = std::shared_ptr> - static VOID WINAPI service_main_start(D argc, TStr *argv) - { - extern Ptr service_info; - - service_info->service_handle = RegisterServiceCtrlHandler( - service_info->service_name, - service::ServiceControlHandler::ServiceCtrlHandler); - - if (!service_info->service_handle) - { - return; - } - - notify_service_controller_starting(service_info); - - - if (!starting_service(service_info)) - { - return; - } - - notify_service_controller_started(service_info); - - // Start a thread that will perform the main task of the service - Handle hThread = CreateThread(nullptr, 0, ServiceWorkerThread, nullptr, 0, nullptr); - - // Wait until our worker thread exits signaling that the service needs to stop - WaitForSingleObject(hThread, INFINITE); - - - close_handle(service_info); - } - private: - template, - typename Ptr = std::shared_ptr> - static D WINAPI ServiceWorkerThread(Lp lpParam) - { - extern Ptr service_info; - - const auto INTERVAL = 1500; - - const auto some_file_path = "C:\\example_file.txt"; - - while (WaitForSingleObject(service_info->service_stop_event, 0) != WAIT_OBJECT_0) - { - std::fstream file(some_file_path, std::ios::out | std::ios::app); - - const auto content = "burrow"; - - file << content << "\n"; - - file.close(); - - Sleep(INTERVAL); - } - - - return ERROR_SUCCESS; - } - - - template, - typename Ptr = std::shared_ptr> - static bool starting_service(Ptr service_info) - { - /* - * Perform tasks necessary to start the service here - */ - - // Create a service stop event to wait on later - service_info->service_stop_event = CreateEvent(nullptr, TRUE, FALSE, nullptr); - if (service_info->service_stop_event == nullptr) - { - // Error creating event - // Tell service controller we are stopped and exit - service_info->service_status.dwControlsAccepted = 0; - service_info->service_status.dwCurrentState = SERVICE_STOPPED; - service_info->service_status.dwWin32ExitCode = GetLastError(); - service_info->service_status.dwCheckPoint = 1; - - if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) - { - OutputDebugString(_T( - "My Sample Service: ServiceMain: SetServiceStatus returned error")); - } - - return false; - } - - return true; - } - - - template, - typename Ptr = std::shared_ptr> - static void close_handle(Ptr service_info) - { - /* - * Perform any cleanup tasks - */ - - CloseHandle(service_info->service_stop_event); - - // Tell the service controller we are stopped - service_info->service_status.dwControlsAccepted = 0; - service_info->service_status.dwCurrentState = SERVICE_STOPPED; - service_info->service_status.dwWin32ExitCode = 0; - service_info->service_status.dwCheckPoint = 3; - - if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) - { - OutputDebugString(_T( - "My Sample Service: ServiceMain: SetServiceStatus returned error")); - } - } - - template, - typename Ptr = std::shared_ptr> - static void notify_service_controller_starting(Ptr service_info) - { - // Tell the service controller we are starting - ZeroMemory(&service_info->service_status, sizeof(service_info->service_status)); - service_info->service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - service_info->service_status.dwControlsAccepted = 0; - service_info->service_status.dwCurrentState = SERVICE_START_PENDING; - service_info->service_status.dwWin32ExitCode = 0; - service_info->service_status.dwServiceSpecificExitCode = 0; - service_info->service_status.dwCheckPoint = 0; - - if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) - { - OutputDebugString(_T( - "My Sample Service: ServiceMain: SetServiceStatus returned error")); - } - } - - template, - typename Ptr = std::shared_ptr> - static void notify_service_controller_started(Ptr service_info) - { - // Tell the service controller we are started - service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; - service_info->service_status.dwCurrentState = SERVICE_RUNNING; - service_info->service_status.dwWin32ExitCode = 0; - service_info->service_status.dwCheckPoint = 0; - - if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) - { - OutputDebugString(_T( - "My Sample Service: ServiceMain: SetServiceStatus returned error")); - } - } - }; -} - -#endif \ No newline at end of file +#ifndef SERVICEENTRYPOINT_H_ +#define SERVICEENTRYPOINT_H_ + +#include +#include + +#include +#include +#include + +#include "Models.h" +#include "ServiceControlHandler.hpp" + +namespace service +{ + class ServiceEntryPoint + { + public: + ServiceEntryPoint() = default; + + template, + typename Ptr = std::shared_ptr> + static VOID WINAPI service_main_start(D argc, TStr *argv) + { + extern Ptr service_info; + + service_info->service_handle = RegisterServiceCtrlHandler( + service_info->service_name, + service::ServiceControlHandler::ServiceCtrlHandler); + + if (!service_info->service_handle) + { + return; + } + + notify_service_controller_starting(service_info); + + + if (!starting_service(service_info)) + { + return; + } + + notify_service_controller_started(service_info); + + // Start a thread that will perform the main task of the service + Handle hThread = CreateThread(nullptr, 0, ServiceWorkerThread, nullptr, 0, nullptr); + + // Wait until our worker thread exits signaling that the service needs to stop + WaitForSingleObject(hThread, INFINITE); + + + close_handle(service_info); + } + private: + template, + typename Ptr = std::shared_ptr> + static D WINAPI ServiceWorkerThread(Lp lpParam) + { + extern Ptr service_info; + + const auto INTERVAL = 1500; + + const auto some_file_path = "C:\\example_file.txt"; + + while (WaitForSingleObject(service_info->service_stop_event, 0) != WAIT_OBJECT_0) + { + std::fstream file(some_file_path, std::ios::out | std::ios::app); + + const auto content = "burrow"; + + file << content << "\n"; + + file.close(); + + Sleep(INTERVAL); + } + + + return ERROR_SUCCESS; + } + + + template, + typename Ptr = std::shared_ptr> + static bool starting_service(Ptr service_info) + { + /* + * Perform tasks necessary to start the service here + */ + + // Create a service stop event to wait on later + service_info->service_stop_event = CreateEvent(nullptr, TRUE, FALSE, nullptr); + if (service_info->service_stop_event == nullptr) + { + // Error creating event + // Tell service controller we are stopped and exit + service_info->service_status.dwControlsAccepted = 0; + service_info->service_status.dwCurrentState = SERVICE_STOPPED; + service_info->service_status.dwWin32ExitCode = GetLastError(); + service_info->service_status.dwCheckPoint = 1; + + if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) + { + OutputDebugString(_T( + "My Sample Service: ServiceMain: SetServiceStatus returned error")); + } + + return false; + } + + return true; + } + + + template, + typename Ptr = std::shared_ptr> + static void close_handle(Ptr service_info) + { + /* + * Perform any cleanup tasks + */ + + CloseHandle(service_info->service_stop_event); + + // Tell the service controller we are stopped + service_info->service_status.dwControlsAccepted = 0; + service_info->service_status.dwCurrentState = SERVICE_STOPPED; + service_info->service_status.dwWin32ExitCode = 0; + service_info->service_status.dwCheckPoint = 3; + + if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) + { + OutputDebugString(_T( + "My Sample Service: ServiceMain: SetServiceStatus returned error")); + } + } + + template, + typename Ptr = std::shared_ptr> + static void notify_service_controller_starting(Ptr service_info) + { + // Tell the service controller we are starting + ZeroMemory(&service_info->service_status, sizeof(service_info->service_status)); + service_info->service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; + service_info->service_status.dwControlsAccepted = 0; + service_info->service_status.dwCurrentState = SERVICE_START_PENDING; + service_info->service_status.dwWin32ExitCode = 0; + service_info->service_status.dwServiceSpecificExitCode = 0; + service_info->service_status.dwCheckPoint = 0; + + if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) + { + OutputDebugString(_T( + "My Sample Service: ServiceMain: SetServiceStatus returned error")); + } + } + + template, + typename Ptr = std::shared_ptr> + static void notify_service_controller_started(Ptr service_info) + { + // Tell the service controller we are started + service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; + service_info->service_status.dwCurrentState = SERVICE_RUNNING; + service_info->service_status.dwWin32ExitCode = 0; + service_info->service_status.dwCheckPoint = 0; + + if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) + { + OutputDebugString(_T( + "My Sample Service: ServiceMain: SetServiceStatus returned error")); + } + } + }; +} + +#endif diff --git a/ServiceExample/ServiceExample.vcxproj b/ServiceExample/ServiceExample.vcxproj index 2d4619d..c17116c 100644 --- a/ServiceExample/ServiceExample.vcxproj +++ b/ServiceExample/ServiceExample.vcxproj @@ -1,93 +1,93 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {19AD11CD-7C72-41C6-B372-32A63C2EAB7A} - Win32Proj - ServiceExample - - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - true - C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\include;$(IncludePath) - C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\bin;C:\Windows\System32;$(LibraryPath) - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\lib;%(AdditionalLibraryDirectories) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {19AD11CD-7C72-41C6-B372-32A63C2EAB7A} + Win32Proj + ServiceExample + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\include;$(IncludePath) + C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\bin;C:\Windows\System32;$(LibraryPath) + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + \ No newline at end of file