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

📄 objectserviceinternal.cpp

📁 .net 方面的开发说明资料。
💻 CPP
字号:
// =====================================================
// OpenNet Integrated Services
//
// Design and Implementation by Floris van den Berg
//
// Copyright (c) 2002 Pylon
// =====================================================

#pragma warning (disable : 4275)
#pragma warning (disable : 4786)

#include <io.h>
#include <list>
#include <map>
#include <string>
#include <windows.h>

#include "OpenObjects.h"
#include "ObjectServiceInternal.h"

// -----------------------------------------------------

class CInternalService : public IService {
public:
	CInternalService();
	virtual unsigned long DLL_CALLCONV AddRef();
	virtual unsigned long DLL_CALLCONV Release();
	virtual HRESULT DLL_CALLCONV QueryInterface(REFIID guid, void **iif);
	virtual HRESULT DLL_CALLCONV CreateInstance(GUID family, GUID guid, void **object);
	virtual bool DLL_CALLCONV ObjectExists(GUID family, GUID guid);
	virtual bool DLL_CALLCONV RegisterComponent(GUID family, GUID guid, ObjectCreateProc proc);
	~CInternalService();

private :
	unsigned int m_ref_count;
	_STL::list<ObjectInfo *> m_info_list;
};

// -----------------------------------------------------

CInternalService::CInternalService() :
m_ref_count(0),
m_info_list() {
}

CInternalService::~CInternalService() {
	for (_STL::list<ObjectInfo *>::iterator it = m_info_list.begin(); it != m_info_list.end(); ++it)
		delete *it;
}

unsigned long DLL_CALLCONV
CInternalService::AddRef() {
	return ++m_ref_count;
}

unsigned long DLL_CALLCONV
CInternalService::Release() {
	int ref = --m_ref_count;

	if (ref == 0)
		delete this;

	return ref - 1;
}

HRESULT
CInternalService::QueryInterface(REFIID guid, void **iif) {
	if (IsEqualGUID(guid, CLSID_SERVICE_REGISTERABLE)) {
		AddRef();
		*iif = this;
		return S_OK;
	} else if (IsEqualGUID(guid, GUID_OBJECT)) {
		AddRef();
		*iif = this;
		return S_OK;
	}

	return E_NOINTERFACE;
}


HRESULT DLL_CALLCONV
CInternalService::CreateInstance(GUID family, GUID guid, void **object) {
	for (_STL::list<ObjectInfo *>::iterator it = m_info_list.begin(); it != m_info_list.end(); ++it)
		if (IsEqualGUID(guid, (*it)->guid))
			if (IsEqualGUID(family, (*it)->family))
				return (*it)->create(object);

	return E_FAIL;
}

bool DLL_CALLCONV
CInternalService::ObjectExists(GUID family, GUID guid) {
	for (_STL::list<ObjectInfo *>::iterator it = m_info_list.begin(); it != m_info_list.end(); ++it)
		if (IsEqualGUID(guid, (*it)->guid))
			if (IsEqualGUID(family, (*it)->family))
				return true;

	return false;
};

bool DLL_CALLCONV
CInternalService::RegisterComponent(GUID family, GUID guid, ObjectCreateProc create) {
	ObjectInfo *info = new ObjectInfo;
	info->family = family;
	info->guid = guid;
	info->create = create;
	info->extra = NULL;

	m_info_list.push_back(info);
	return true;
}

// -----------------------------------------------------

HRESULT DLL_CALLCONV
CInternalServiceCreate(void **iif) {
	CInternalService *object = new CInternalService;

	if (object) {
		object->AddRef();
		*iif = object;
		return S_OK;
	}

	return E_FAIL;
}

⌨️ 快捷键说明

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