- 8
- 0
- 约1.42万字
- 约 12页
- 2016-08-15 发布于重庆
- 举报
C中COM对象INTERFACE接口和接口基类三者的构建模型
《C++中COM对象 INTERFACE接口 和接口基类三者的构建模型》
(一) 用以实例化COM基类并对其引用进行计数的共享模板类ShareObject:
(均在同一个文件:ShareObject.h中)
//===================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED AS IS WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
#pragma once
#include Unknwn.h
///LWW:本文件中,若想剔除ShareObjectT模板类对ComPtr.h头文件的依赖,实现更好的独立性,可将本文件中用///oo///打头的代码代替其对应代码,
/// 并将无对应代码的行解除注销即可,共涉及5处地方;
///oo/// #include ComPtr.h
#include ComPtr.h
// Used for initialization of a COM Object
// Implement this interface if you require your COMObject
// to do initialization after its created.
[uuid(0B3B5912-31A9-49C2-B195-DCABB870AB59)]
__interface IInitializable : public IUnknown
{
// This function is called right after the object is constructed
// WARNING: Dont call AddRef() or Release() for the current object
// inside this function
HRESULT __stdcall Initialize();
};
//
// This class encapsulates an IUnknown based object,
// and implements AddRef, Relase and QueryInterface
// However, QueryInterface requires a helper function: T::QueryInterfaceHelper(IID const, void**)
// that must be implented by all classes using the COMObject
// WARNING: Dont call AddRef() or Release() in the current objects constructor
//
template class T
class SharedObject: public T
{
public:
template class I
static HRESULT Create(__out I** object)
{
///LWW:://如何自定义判断I是T的基类的方法?来取代std::tr1::is_base_ofI, T::value?
stati
原创力文档

文档评论(0)