⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nt_service_exception.hpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 HPP
字号:

//         Copyright E骾n O'Callaghan 2008 - 2008.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#ifndef NT_SERVICE_EXCEPTION_HPP_INCLUDED
#define NT_SERVICE_EXCEPTION_HPP_INCLUDED

#include "StdAfx.hpp"

class nt_service_exception
{
public:
	nt_service_exception(LPCTSTR lpServiceName, DWORD error) :
		lpServiceName_(lpServiceName),
		error_(error)
	{}

	LPCTSTR lpServiceName() const { return lpServiceName_; }
	DWORD error() const { return error_; }

private:
	LPCTSTR lpServiceName_;
	DWORD error_;
};

// All just meant as veneer type aliases
class access_denied : public nt_service_exception
{
public:
	access_denied(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_ACCESS_DENIED)
	{}
};

class invalid_handle : public nt_service_exception
{
public:
	invalid_handle(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_INVALID_HANDLE)
	{}
};

class invalid_name : public nt_service_exception
{
public:
	invalid_name(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_INVALID_NAME)
	{}
};

class service_does_not_exist : public nt_service_exception
{
public:
	service_does_not_exist(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_SERVICE_DOES_NOT_EXIST)
	{}
};

class insufficient_buffer : public nt_service_exception
{
public:
	insufficient_buffer(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_INSUFFICIENT_BUFFER)
	{}
};

class invalid_parameter : public nt_service_exception
{
public:
	invalid_parameter(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_INVALID_PARAMETER)
	{}
};

class invalid_level : public nt_service_exception
{
public:
	invalid_level(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_INVALID_LEVEL)
	{}
};

class shutdown_in_progress : public nt_service_exception
{
public:
	shutdown_in_progress(LPCTSTR lpServiceName) :
		nt_service_exception(lpServiceName, ERROR_SHUTDOWN_IN_PROGRESS)
	{}
};

inline void throw_nt_service_exception(LPCTSTR lpServiceName, DWORD error=GetLastError())
{
/*	switch (error)
	{
	case ERROR_ACCESS_DENIED:
		throw access_denied(lpServiceName);
	case ERROR_INVALID_HANDLE:
		throw invalid_handle(lpServiceName);
	case ERROR_INVALID_NAME:
		throw invalid_name(lpServiceName);
	case ERROR_SERVICE_DOES_NOT_EXIST:
		throw service_does_not_exist(lpServiceName);
	case ERROR_INSUFFICIENT_BUFFER:
		throw insufficient_buffer(lpServiceName);
	case ERROR_INVALID_PARAMETER:
		throw invalid_parameter(lpServiceName);
	case ERROR_INVALID_LEVEL:
		throw invalid_level(lpServiceName);
	case ERROR_SHUTDOWN_IN_PROGRESS:
		throw shutdown_in_progress(lpServiceName);
	default:*/
		throw nt_service_exception(lpServiceName, error);
//	}
}

inline std::wstring nt_service_erorr_to_string(DWORD error)
{
	switch (error)
	{
	case ERROR_ACCESS_DENIED:
		return L"Access denied";
	case ERROR_INVALID_HANDLE:
		return L"Invalid handle";
	case ERROR_INVALID_NAME:
		return L"Invalid name";
	case ERROR_SERVICE_DOES_NOT_EXIST:
		return L"Service does not exist";
	case ERROR_INSUFFICIENT_BUFFER:
		return L"Insufficent buffer";
	case ERROR_INVALID_PARAMETER:
		return L"Invalid parameter";
	case ERROR_INVALID_LEVEL:
		return L"Invalid level";
	case ERROR_SHUTDOWN_IN_PROGRESS:
		return L"Shutdown in progress";
	case ERROR_SERVICE_MARKED_FOR_DELETE:
		return L"Service marked for delete";
	case ERROR_INVALID_SERVICE_ACCOUNT:
		return L"Invalid service account";
	case ERROR_CIRCULAR_DEPENDENCY:
		return L"Error circular dependency";
	case ERROR_DUPLICATE_SERVICE_NAME:
		return L"Duplicate service name";
	case ERROR_PATH_NOT_FOUND:
		return L"Path not found";
	case ERROR_SERVICE_ALREADY_RUNNING:
		return L"Service already running";
	case ERROR_SERVICE_DATABASE_LOCKED:
		return L"Service database locked";
	case ERROR_SERVICE_DEPENDENCY_FAIL:
		return L"Service dependency fail";
	case ERROR_SERVICE_DISABLED:
		return L"Service has been disabled";
	case ERROR_SERVICE_NO_THREAD:
		return L"Service no thread";
	case ERROR_SERVICE_REQUEST_TIMEOUT:
		return L"Service request timeout";
	case ERROR_DEPENDENT_SERVICES_RUNNING:
		return L"Dependent services running";
	case ERROR_INVALID_SERVICE_CONTROL:
		return L"Invalid service control";
	case ERROR_SERVICE_CANNOT_ACCEPT_CTRL:
		return L"Service cannot accept control";
	case ERROR_SERVICE_NOT_ACTIVE:
		return L"Service not active";
	default:
		return L"NT Service error";
	}
}

#endif // NT_SERVICE_EXCEPTION_HPP_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -