Formatting changes

This commit is contained in:
kdeng00
2020-12-05 23:20:40 -05:00
parent 37af458d5f
commit 12450e2f0e
6 changed files with 559 additions and 559 deletions
+22 -22
View File
@@ -1,22 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 2013
VisualStudioVersion = 12.0.40629.0 VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServiceExample", "ServiceExample\ServiceExample.vcxproj", "{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServiceExample", "ServiceExample\ServiceExample.vcxproj", "{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32 Release|Win32 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Debug|Win32.ActiveCfg = Debug|Win32 {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}.Debug|Win32.Build.0 = Debug|Win32
{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.ActiveCfg = Release|Win32 {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.ActiveCfg = Release|Win32
{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.Build.0 = Release|Win32 {19AD11CD-7C72-41C6-B372-32A63C2EAB7A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
+148 -148
View File
@@ -1,148 +1,148 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <memory> #include <memory>
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#include <strsafe.h> #include <strsafe.h>
#pragma comment(lib, "advapi32.lib") #pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "kernel32.lib") #pragma comment(lib, "kernel32.lib")
#include "Models.h" #include "Models.h"
#include "ServiceEntryPoint.hpp" #include "ServiceEntryPoint.hpp"
template<typename Handle = SC_HANDLE, typename Char = wchar_t> template<typename Handle = SC_HANDLE, typename Char = wchar_t>
VOID ServiceInstall(void); VOID ServiceInstall(void);
template<typename TSTR = LPTSTR, typename CTSTR = LPCTSTR, template<typename TSTR = LPTSTR, typename CTSTR = LPCTSTR,
typename Handle = HANDLE, typename Char = TCHAR> typename Handle = HANDLE, typename Char = TCHAR>
VOID ServiceReportEvent(LPTSTR); VOID ServiceReportEvent(LPTSTR);
std::shared_ptr<models::ServiceInfo<>> service_info(new models::ServiceInfo<>(L"Service Example")); std::shared_ptr<models::ServiceInfo<>> service_info(new models::ServiceInfo<>(L"Service Example"));
#undef main #undef main
int _tmain(int argc, TCHAR *argv[]) int _tmain(int argc, TCHAR *argv[])
{ {
std::cout << "ServiceExample\n"; std::cout << "ServiceExample\n";
if (lstrcmpi(argv[1], TEXT("install")) == 0) if (lstrcmpi(argv[1], TEXT("install")) == 0)
{ {
ServiceInstall(); ServiceInstall();
return -1; return -1;
} }
SERVICE_TABLE_ENTRY SERVICETABLE[] = SERVICE_TABLE_ENTRY SERVICETABLE[] =
{ {
{ service_info->service_name, { service_info->service_name,
(LPSERVICE_MAIN_FUNCTION) (LPSERVICE_MAIN_FUNCTION)
service::ServiceEntryPoint::service_main_start }, service::ServiceEntryPoint::service_main_start },
{ nullptr, nullptr }, { nullptr, nullptr },
}; };
if (!StartServiceCtrlDispatcher(SERVICETABLE)) if (!StartServiceCtrlDispatcher(SERVICETABLE))
{ {
auto func = reinterpret_cast<LPTSTR>(TEXT("StartServiceCtrlDispatcher")); auto func = reinterpret_cast<LPTSTR>(TEXT("StartServiceCtrlDispatcher"));
ServiceReportEvent(func); ServiceReportEvent(func);
} }
return 0; return 0;
} }
template<typename Handle, typename Char> template<typename Handle, typename Char>
VOID ServiceInstall() VOID ServiceInstall()
{ {
Char buffer[MAX_PATH]; Char buffer[MAX_PATH];
if (!GetModuleFileName(nullptr, buffer, MAX_PATH)) if (!GetModuleFileName(nullptr, buffer, MAX_PATH))
{ {
std::cout << "Cannot install service " << GetLastError() << "\n"; std::cout << "Cannot install service " << GetLastError() << "\n";
return; return;
} }
// Get a handle to the SCM database. // Get a handle to the SCM database.
Handle schSCManager = OpenSCManager( Handle schSCManager = OpenSCManager(
nullptr, // local computer nullptr, // local computer
nullptr, // ServicesActive database nullptr, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights SC_MANAGER_ALL_ACCESS); // full access rights
if (nullptr == schSCManager) if (nullptr == schSCManager)
{ {
std::cout << "OpenSCManager failed " << GetLastError() << "\n"; std::cout << "OpenSCManager failed " << GetLastError() << "\n";
return; return;
} }
// Create the service // Create the service
Handle schService = CreateService( Handle schService = CreateService(
schSCManager, // SCM database schSCManager, // SCM database
service_info->service_name, // name of service service_info->service_name, // name of service
service_info->service_name, // service name to display service_info->service_name, // service name to display
SERVICE_ALL_ACCESS, // desired access SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type SERVICE_ERROR_NORMAL, // error control type
buffer, // path to service's binary buffer, // path to service's binary
nullptr, // no load ordering group nullptr, // no load ordering group
nullptr, // no tag identifier nullptr, // no tag identifier
nullptr, // no dependencies nullptr, // no dependencies
nullptr, // LocalSystem account nullptr, // LocalSystem account
nullptr); // no password nullptr); // no password
if (schService == nullptr) if (schService == nullptr)
{ {
std::cout << "CreateService failed " << GetLastError() << "\n"; std::cout << "CreateService failed " << GetLastError() << "\n";
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
return; return;
} }
else else
{ {
std::cout << "Service installed successfully\n"; std::cout << "Service installed successfully\n";
} }
CloseServiceHandle(schService); CloseServiceHandle(schService);
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
} }
template<typename TStr, typename CTStr, template<typename TStr, typename CTStr,
typename Handle, typename Char> typename Handle, typename Char>
VOID ServiceReportEvent(LPTSTR szFunction) VOID ServiceReportEvent(LPTSTR szFunction)
{ {
CTStr lpszStrings[2]; CTStr lpszStrings[2];
Char Buffer[80]; Char Buffer[80];
Handle hEventSource = RegisterEventSource(nullptr, service_info->service_name); Handle hEventSource = RegisterEventSource(nullptr, service_info->service_name);
if (nullptr != hEventSource) if (nullptr != hEventSource)
{ {
StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError()); StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError());
lpszStrings[0] = service_info->service_name; lpszStrings[0] = service_info->service_name;
lpszStrings[1] = Buffer; lpszStrings[1] = Buffer;
ReportEvent(hEventSource, // event log handle ReportEvent(hEventSource, // event log handle
EVENTLOG_ERROR_TYPE, // event type EVENTLOG_ERROR_TYPE, // event type
0, // event category 0, // event category
SERVICE_ERROR_NORMAL, // event identifier SERVICE_ERROR_NORMAL, // event identifier
nullptr, // no security identifier nullptr, // no security identifier
2, // size of lpszStrings array 2, // size of lpszStrings array
0, // no binary data 0, // no binary data
lpszStrings, // array of strings lpszStrings, // array of strings
nullptr); // no binary data nullptr); // no binary data
DeregisterEventSource(hEventSource); DeregisterEventSource(hEventSource);
} }
} }
+34 -34
View File
@@ -1,34 +1,34 @@
#ifndef MODELS_H_ #ifndef MODELS_H_
#define MODELS_H_ #define MODELS_H_
#include <string> #include <string>
namespace models namespace models
{ {
template<typename Str = std::wstring, template<typename Str = std::wstring,
typename Char = wchar_t, typename Char = wchar_t,
typename Status = SERVICE_STATUS, typename Status = SERVICE_STATUS,
typename StatusHandle = SERVICE_STATUS_HANDLE, typename StatusHandle = SERVICE_STATUS_HANDLE,
typename Handle = HANDLE> typename Handle = HANDLE>
class ServiceInfo class ServiceInfo
{ {
public: public:
ServiceInfo() ServiceInfo()
{ {
service_stop_event = INVALID_HANDLE_VALUE; service_stop_event = INVALID_HANDLE_VALUE;
} }
ServiceInfo(std::wstring &&name) : ServiceInfo(std::wstring &&name) :
service_name(const_cast<wchar_t*>(name.c_str())) service_name(const_cast<wchar_t*>(name.c_str()))
{ {
service_stop_event = INVALID_HANDLE_VALUE; service_stop_event = INVALID_HANDLE_VALUE;
} }
wchar_t *service_name; wchar_t *service_name;
Status service_status; Status service_status;
StatusHandle service_handle; StatusHandle service_handle;
Handle service_stop_event; Handle service_stop_event;
}; };
} }
#endif #endif
+82 -82
View File
@@ -1,82 +1,82 @@
#ifndef SERVICECONTROLHANDLER_H_ #ifndef SERVICECONTROLHANDLER_H_
#define SERVICECONTROLHANDLER_H_ #define SERVICECONTROLHANDLER_H_
#include <memory> #include <memory>
#include <Windows.h> #include <Windows.h>
#include <tchar.h> #include <tchar.h>
#include <strsafe.h> #include <strsafe.h>
#include "Models.h" #include "Models.h"
namespace service namespace service
{ {
class ServiceControlHandler class ServiceControlHandler
{ {
public: public:
template<typename D = DWORD, template<typename D = DWORD,
typename Obj = models::ServiceInfo<>, typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static VOID WINAPI ServiceCtrlHandler(D ctrlCode) static VOID WINAPI ServiceCtrlHandler(D ctrlCode)
{ {
extern Ptr service_info; extern Ptr service_info;
switch (ctrlCode) switch (ctrlCode)
{ {
case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_STOP:
ReportServiceStatus<D>(SERVICE_STOP_PENDING, NO_ERROR, 0); ReportServiceStatus<D>(SERVICE_STOP_PENDING, NO_ERROR, 0);
SetEvent(service_info->service_stop_event); SetEvent(service_info->service_stop_event);
ReportServiceStatus<D>(service_info->service_status.dwCurrentState, NO_ERROR, 0); ReportServiceStatus<D>(service_info->service_status.dwCurrentState, NO_ERROR, 0);
return; return;
case SERVICE_CONTROL_INTERROGATE: case SERVICE_CONTROL_INTERROGATE:
break; break;
default: default:
break; break;
} }
} }
template<typename D = DWORD, template<typename D = DWORD,
typename Obj = models::ServiceInfo<>, typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static VOID ReportServiceStatus(D dwCurrentState, static VOID ReportServiceStatus(D dwCurrentState,
D dwWin32ExitCode, D dwWin32ExitCode,
D dwWaitHint) D dwWaitHint)
{ {
extern Ptr service_info; extern Ptr service_info;
static D dwCheckPoint = 1; static D dwCheckPoint = 1;
service_info->service_status.dwCurrentState = dwCurrentState; service_info->service_status.dwCurrentState = dwCurrentState;
service_info->service_status.dwWin32ExitCode = dwWin32ExitCode; service_info->service_status.dwWin32ExitCode = dwWin32ExitCode;
service_info->service_status.dwWaitHint = dwWaitHint; service_info->service_status.dwWaitHint = dwWaitHint;
if (dwCurrentState == SERVICE_START_PENDING) if (dwCurrentState == SERVICE_START_PENDING)
{ {
service_info->service_status.dwControlsAccepted = 0; service_info->service_status.dwControlsAccepted = 0;
} }
else else
{ {
service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
} }
if ((dwCurrentState == SERVICE_RUNNING) || if ((dwCurrentState == SERVICE_RUNNING) ||
(dwCurrentState == SERVICE_STOPPED)) (dwCurrentState == SERVICE_STOPPED))
{ {
service_info->service_status.dwCheckPoint = 0; service_info->service_status.dwCheckPoint = 0;
} }
else else
{ {
service_info->service_status.dwCheckPoint = dwCheckPoint++; service_info->service_status.dwCheckPoint = dwCheckPoint++;
} }
SetServiceStatus(service_info->service_handle, &service_info->service_status); SetServiceStatus(service_info->service_handle, &service_info->service_status);
} }
private: private:
}; };
} }
#endif #endif
+181 -181
View File
@@ -1,181 +1,181 @@
#ifndef SERVICEENTRYPOINT_H_ #ifndef SERVICEENTRYPOINT_H_
#define SERVICEENTRYPOINT_H_ #define SERVICEENTRYPOINT_H_
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#include <strsafe.h> #include <strsafe.h>
#include "Models.h" #include "Models.h"
#include "ServiceControlHandler.hpp" #include "ServiceControlHandler.hpp"
namespace service namespace service
{ {
class ServiceEntryPoint class ServiceEntryPoint
{ {
public: public:
ServiceEntryPoint() = default; ServiceEntryPoint() = default;
template<typename D = DWORD, typename TStr = LPTSTR, template<typename D = DWORD, typename TStr = LPTSTR,
typename Handle = HANDLE, typename Handle = HANDLE,
typename Obj = models::ServiceInfo<>, typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static VOID WINAPI service_main_start(D argc, TStr *argv) static VOID WINAPI service_main_start(D argc, TStr *argv)
{ {
extern Ptr service_info; extern Ptr service_info;
service_info->service_handle = RegisterServiceCtrlHandler( service_info->service_handle = RegisterServiceCtrlHandler(
service_info->service_name, service_info->service_name,
service::ServiceControlHandler::ServiceCtrlHandler); service::ServiceControlHandler::ServiceCtrlHandler);
if (!service_info->service_handle) if (!service_info->service_handle)
{ {
return; return;
} }
notify_service_controller_starting(service_info); notify_service_controller_starting(service_info);
if (!starting_service(service_info)) if (!starting_service(service_info))
{ {
return; return;
} }
notify_service_controller_started(service_info); notify_service_controller_started(service_info);
// Start a thread that will perform the main task of the service // Start a thread that will perform the main task of the service
Handle hThread = CreateThread(nullptr, 0, ServiceWorkerThread, nullptr, 0, nullptr); Handle hThread = CreateThread(nullptr, 0, ServiceWorkerThread, nullptr, 0, nullptr);
// Wait until our worker thread exits signaling that the service needs to stop // Wait until our worker thread exits signaling that the service needs to stop
WaitForSingleObject(hThread, INFINITE); WaitForSingleObject(hThread, INFINITE);
close_handle(service_info); close_handle(service_info);
} }
private: private:
template<typename D = DWORD, typename Lp = LPVOID, template<typename D = DWORD, typename Lp = LPVOID,
typename Obj = models::ServiceInfo<>, typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static D WINAPI ServiceWorkerThread(Lp lpParam) static D WINAPI ServiceWorkerThread(Lp lpParam)
{ {
extern Ptr service_info; extern Ptr service_info;
const auto INTERVAL = 1500; const auto INTERVAL = 1500;
const auto some_file_path = "C:\\example_file.txt"; const auto some_file_path = "C:\\example_file.txt";
while (WaitForSingleObject(service_info->service_stop_event, 0) != WAIT_OBJECT_0) while (WaitForSingleObject(service_info->service_stop_event, 0) != WAIT_OBJECT_0)
{ {
std::fstream file(some_file_path, std::ios::out | std::ios::app); std::fstream file(some_file_path, std::ios::out | std::ios::app);
const auto content = "burrow"; const auto content = "burrow";
file << content << "\n"; file << content << "\n";
file.close(); file.close();
Sleep(INTERVAL); Sleep(INTERVAL);
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
template<typename Obj = models::ServiceInfo<>, template<typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static bool starting_service(Ptr service_info) static bool starting_service(Ptr service_info)
{ {
/* /*
* Perform tasks necessary to start the service here * Perform tasks necessary to start the service here
*/ */
// Create a service stop event to wait on later // Create a service stop event to wait on later
service_info->service_stop_event = CreateEvent(nullptr, TRUE, FALSE, nullptr); service_info->service_stop_event = CreateEvent(nullptr, TRUE, FALSE, nullptr);
if (service_info->service_stop_event == nullptr) if (service_info->service_stop_event == nullptr)
{ {
// Error creating event // Error creating event
// Tell service controller we are stopped and exit // Tell service controller we are stopped and exit
service_info->service_status.dwControlsAccepted = 0; service_info->service_status.dwControlsAccepted = 0;
service_info->service_status.dwCurrentState = SERVICE_STOPPED; service_info->service_status.dwCurrentState = SERVICE_STOPPED;
service_info->service_status.dwWin32ExitCode = GetLastError(); service_info->service_status.dwWin32ExitCode = GetLastError();
service_info->service_status.dwCheckPoint = 1; service_info->service_status.dwCheckPoint = 1;
if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE)
{ {
OutputDebugString(_T( OutputDebugString(_T(
"My Sample Service: ServiceMain: SetServiceStatus returned error")); "My Sample Service: ServiceMain: SetServiceStatus returned error"));
} }
return false; return false;
} }
return true; return true;
} }
template<typename Obj = models::ServiceInfo<>, template<typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static void close_handle(Ptr service_info) static void close_handle(Ptr service_info)
{ {
/* /*
* Perform any cleanup tasks * Perform any cleanup tasks
*/ */
CloseHandle(service_info->service_stop_event); CloseHandle(service_info->service_stop_event);
// Tell the service controller we are stopped // Tell the service controller we are stopped
service_info->service_status.dwControlsAccepted = 0; service_info->service_status.dwControlsAccepted = 0;
service_info->service_status.dwCurrentState = SERVICE_STOPPED; service_info->service_status.dwCurrentState = SERVICE_STOPPED;
service_info->service_status.dwWin32ExitCode = 0; service_info->service_status.dwWin32ExitCode = 0;
service_info->service_status.dwCheckPoint = 3; service_info->service_status.dwCheckPoint = 3;
if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE)
{ {
OutputDebugString(_T( OutputDebugString(_T(
"My Sample Service: ServiceMain: SetServiceStatus returned error")); "My Sample Service: ServiceMain: SetServiceStatus returned error"));
} }
} }
template<typename Obj = models::ServiceInfo<>, template<typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static void notify_service_controller_starting(Ptr service_info) static void notify_service_controller_starting(Ptr service_info)
{ {
// Tell the service controller we are starting // Tell the service controller we are starting
ZeroMemory(&service_info->service_status, sizeof(service_info->service_status)); ZeroMemory(&service_info->service_status, sizeof(service_info->service_status));
service_info->service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; service_info->service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
service_info->service_status.dwControlsAccepted = 0; service_info->service_status.dwControlsAccepted = 0;
service_info->service_status.dwCurrentState = SERVICE_START_PENDING; service_info->service_status.dwCurrentState = SERVICE_START_PENDING;
service_info->service_status.dwWin32ExitCode = 0; service_info->service_status.dwWin32ExitCode = 0;
service_info->service_status.dwServiceSpecificExitCode = 0; service_info->service_status.dwServiceSpecificExitCode = 0;
service_info->service_status.dwCheckPoint = 0; service_info->service_status.dwCheckPoint = 0;
if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE)
{ {
OutputDebugString(_T( OutputDebugString(_T(
"My Sample Service: ServiceMain: SetServiceStatus returned error")); "My Sample Service: ServiceMain: SetServiceStatus returned error"));
} }
} }
template<typename Obj = models::ServiceInfo<>, template<typename Obj = models::ServiceInfo<>,
typename Ptr = std::shared_ptr<Obj>> typename Ptr = std::shared_ptr<Obj>>
static void notify_service_controller_started(Ptr service_info) static void notify_service_controller_started(Ptr service_info)
{ {
// Tell the service controller we are started // Tell the service controller we are started
service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; service_info->service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
service_info->service_status.dwCurrentState = SERVICE_RUNNING; service_info->service_status.dwCurrentState = SERVICE_RUNNING;
service_info->service_status.dwWin32ExitCode = 0; service_info->service_status.dwWin32ExitCode = 0;
service_info->service_status.dwCheckPoint = 0; service_info->service_status.dwCheckPoint = 0;
if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE) if (SetServiceStatus(service_info->service_handle, &service_info->service_status) == FALSE)
{ {
OutputDebugString(_T( OutputDebugString(_T(
"My Sample Service: ServiceMain: SetServiceStatus returned error")); "My Sample Service: ServiceMain: SetServiceStatus returned error"));
} }
} }
}; };
} }
#endif #endif
+92 -92
View File
@@ -1,93 +1,93 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}</ProjectGuid> <ProjectGuid>{19AD11CD-7C72-41C6-B372-32A63C2EAB7A}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>ServiceExample</RootNamespace> <RootNamespace>ServiceExample</RootNamespace>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\include;$(IncludePath)</IncludePath> <IncludePath>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\bin;C:\Windows\System32;$(LibraryPath)</LibraryPath> <LibraryPath>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\bin;C:\Windows\System32;$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<PrecompiledHeader> <PrecompiledHeader>
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>C:\Users\brahmix\Programming\c++\pre_2015\soci\soci_4_0_0\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<PrecompiledHeader> <PrecompiledHeader>
</PrecompiledHeader> </PrecompiledHeader>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Main.cpp" /> <ClCompile Include="Main.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="BaseService.hpp" /> <ClInclude Include="BaseService.hpp" />
<ClInclude Include="Models.h" /> <ClInclude Include="Models.h" />
<ClInclude Include="ServiceControlHandler.hpp" /> <ClInclude Include="ServiceControlHandler.hpp" />
<ClInclude Include="ServiceEntryPoint.hpp" /> <ClInclude Include="ServiceEntryPoint.hpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>