zoukankan      html  css  js  c++  java
  • ATL 接口映射

    一.BEGIN_COM_MAP && END_COM_MAP

    以BEGIN和END结尾,COM_INTERFACE_ENTRY放中间

    BEGIN_COM_MAP(CRandom)
        COM_INTERFACE_ENTRY(IRandom)
    END_COM_MAP()
    

    二.多重继承问题

    ISphere 造成了歧义,可以用COM_INTERFACE_ENTRY_IID指定默认的实现接口

    interface IGlobe : ISphere {};
    interface IPlanet : ISphere {};
    
    class CDesktopGlobe :
      public CComObjectRootEx<CDesktopGlobe>,
      public IGlobe,
      public IPlanet {
    public:
      ...
    BEGIN_COM_MAP(CDesktopGlobe)
      COM_INTERFACE_ENTRY(ISphere) // ambiguous
      COM_INTERFACE_ENTRY(IGlobe)
      COM_INTERFACE_ENTRY(IPlanet)
    END_COM_MAP()
      // ISphere methods
      ...
      // IGlobe methods
      ...
      // IPlanet methods
      ...
    };
    
    class CDesktopGlobe :
      public CComObjectRootEx<CDesktopGlobe>,
      public IGlobe,
      public IPlanet {
    public:
    ...
    BEGIN_COM_MAP(CDesktopGlobe)
      COM_INTERFACE_ENTRY_IID(IID_ISphere, IGlobe) // unambiguous
      COM_INTERFACE_ENTRY(IGlobe)
      COM_INTERFACE_ENTRY(IPlanet)
    END_COM_MAP()
    ...
    };
    

    三.COM_INTERFACE_ENTRY2 and COM_INTERFACE_ENTRY2_IID

    具有类型转换的效果

    class CDesktopGlobe :
      public CComObjectRootEx<CDesktopGlobe>,
      public IGlobe,
      public IPlanet {
    public:
    ...
    BEGIN_COM_MAP(CDesktopGlobe)
      COM_INTERFACE_ENTRY2(ISphere, IGlobe) // Use the IGlobal branch
      COM_INTERFACE_ENTRY(IGlobe)
      COM_INTERFACE_ENTRY(IPlanet)
    END_COM_MAP()
    ...
    };
    

    四.显示接口

    interface ICowboy : IUnknown {
        HRESULT Draw();
    };
    
    interface IArtist : IUnknown {
       HRESULT Draw();
    };
    class CAcePowell :
        public CComObjectRootEx<CComSingleThreadModel>,
        public ICowboy,
        public IArtist {
    public:
    BEGIN_COM_MAP(CAcePowell)
      COM_INTERFACE_ENTRY(ICowboy)
      COM_INTERFACE_ENTRY(IArtist)
    END_COM_MAP()
    ...
      STDMETHODIMP IArtist::Draw() {
        /* Draw like an artist */
        return S_OK;
      }
    
      STDMETHODIMP ICowboy::Draw() {
        /* Draw like a cowboy */
        return S_OK;
      }
    };
    
    

    避免发生这样的问题

    struct _IArtist : public IArtist {
      STDMETHODIMP Draw() { return ArtistDraw(); }
      STDMETHOD(ArtistDraw)() =0;
    };
    
    struct _ICowboy : public ICowboy {
      STDMETHODIMP Draw() { return CowboyDraw(); }
      STDMETHOD(CowboyDraw)() =0;
    };
    
    class CAcePowell :
        public CComObjectRootEx<CComSingleThreadModel>,
        public _ICowboy,
        public _IArtist {
    public:
    BEGIN_COM_MAP(CAcePowell)
      COM_INTERFACE_ENTRY(ICowboy)
      COM_INTERFACE_ENTRY(IArtist)
    END_COM_MAP()
    ...
      STDMETHODIMP ArtistDraw();
      STDMETHODIMP CowboyDraw();
    };
    
    

    五.COM_INTERFACE_ENTRY_IMPL

    缺省实现派生类

  • 相关阅读:
    SOFT-NMS (二) (non maximum suppression,非极大值抑制)
    NMS(non maximum suppression,非极大值抑制)
    读取txt文件的数据,并将其转换为矩阵
    x.append()增加不同维度的区别
    in __init__ self._traceback = tf_stack.extract_stack()的一个原因
    LoadRunner系列之—-03 用Java Vuser协议编写接口测试脚本
    WebLogic篇----02 控制台性能监控
    soapUI系列之—-01 介绍soapUI简介,groovy 简介
    oracle获取字符串长度函数length()和lengthb()
    soapUI系列之—-06 testrunner实现自动化测试
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/2086350.html
Copyright © 2011-2022 走看看