在END_COM_MAP中IUnknown成员函数的目的是什么? [英] What's the purpose of IUnknown member functions in END_COM_MAP?

查看:253
本文介绍了在END_COM_MAP中IUnknown成员函数的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ATL END_COM_MAP巨集的定义如下:

  #define END_COM_MAP()\ 
__if_exists(_GetAttrEntries) {{NULL,(DWORD_PTR)_GetAttrEntries,_ChainAttr},} \
{NULL,0,0}};返回_entries;} \
virtual ULONG STDMETHODCALLTYPE AddRef(void)throw()= 0; \
virtual ULONG STDMETHODCALLTYPE Release(void)throw()= 0; \
STDMETHOD(QueryInterface)(REFIID,void **)throw()= 0;

它用于从COM接口继承的类的定义中,例如:

  class ATL_NO_VTABLE CMyClass:
public CComCoClass< CMyClass,& MyClassGuid>,
public CComObjectRoot,
public IMyComInterface
{
public:
BEGIN_COM_MAP(CMyClass)
COM_INTERFACE_ENTRY(IMyComInterface)
END_COM_MAP()
};

这意味着QueryInterface(),AddRef()和Release类。因为我没有定义它们的实现,所以这个类应该是不可修改的。



它是如何工作的,为什么这些IUnknown成员函数在这里重新声明? >解决方案

这是一段时间,因为我使用ATL但是,IIRC,什么结束了实例化不是 CMyClass ,但 CComObject< CMyClass>



CComObject implements IUnknown ,并继承其模板参数



编辑: ATL COM对象的基础页面上很好地说明了发生了什么。


ATL END_COM_MAP macro is defined as follows:

#define END_COM_MAP() \
    __if_exists(_GetAttrEntries) {{NULL, (DWORD_PTR)_GetAttrEntries, _ChainAttr }, }\
    {NULL, 0, 0}}; return _entries;} \
    virtual ULONG STDMETHODCALLTYPE AddRef( void) throw() = 0; \
    virtual ULONG STDMETHODCALLTYPE Release( void) throw() = 0; \
    STDMETHOD(QueryInterface)(REFIID, void**) throw() = 0;

It is intended to be used within definition of classes inherited from COM interfaces, for example:

class ATL_NO_VTABLE CMyClass :
    public CComCoClass<CMyClass, &MyClassGuid>,
    public CComObjectRoot,
    public IMyComInterface
{
public:
    BEGIN_COM_MAP( CMyClass )
        COM_INTERFACE_ENTRY( IMyComInterface)
    END_COM_MAP()
};

This means that QueryInterface(), AddRef() and Release() are declared as pure virtual in this class. Since I don't define their implementation this class should be uncreatable. Yet ATL successfully instantiates it.

How does it work and why are those IUnknown member functions redeclared here?

解决方案

It's been a while since I used ATL but, IIRC, what ends up being instantiated is not CMyClass, but CComObject<CMyClass>.

CComObject implements IUnknown and inherits from its template parameter.

Edit: The "Fundamentals of ATL COM Objects" page on MSDN nicely illustrates what's going on.

这篇关于在END_COM_MAP中IUnknown成员函数的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆