KS-AUDIO-COM
+ -

IUnknown

2022-08-23 4 0

与CUnKnow相类似的是IUnknown,其定义如下:

#undef INTERFACE
#define INTERFACE IUnknown
DECLARE_INTERFACE(IUnknown)
{
    STDMETHOD_(NTSTATUS,QueryInterface)
    (   THIS_
        _In_            REFIID,
        _COM_Outptr_    PVOID *
    )   PURE;

    STDMETHOD_(ULONG,AddRef)
    (   THIS
    )   PURE;

    STDMETHOD_(ULONG,Release)
    (   THIS
    )   PURE;
};
#undef INTERFACE

typedef IUnknown *PUNKNOWN;

和CUnKnow一样,其只是一个结构体,其包括三个函数:

#define DECLARE_INTERFACE(iface)    interface DECLSPEC_NOVTABLE iface

而这与CUnknown::m_pUnknownOuter成员DECLARE_STD_UNKNOWN与之相对应。

CUnknown::m_pUnknownOuter成员

默认CUnknown构造为NULL时,使用的是NonDelegating_XX系列函数。但如果不为NULL时,则使用

#define DECLARE_STD_UNKNOWN()                                   \
    STDMETHODIMP_(NTSTATUS) NonDelegatingQueryInterface         \
        (                                                       \
                _In_            REFIID          iid,            \
                _COM_Outptr_    PVOID *     ppvObject           \
        );                                                      \
    STDMETHODIMP_(NTSTATUS) QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv)        \
    {                                                           \
        return GetOuterUnknown()->QueryInterface(riid,ppv);     \
    };                                                          \
    STDMETHODIMP_(ULONG) AddRef()                               \
    {                                                           \
        return GetOuterUnknown()->AddRef();                     \
    };                                                          \
    STDMETHODIMP_(ULONG) Release()                              \
    {                                                           \
        return GetOuterUnknown()->Release();                    \
    };

如对于电源类:

class AdapterPowerMgr: 
     public IAdapterPowerManagement,
     public CUnknown
{

public:
    // Default CUnknown
    DECLARE_STD_UNKNOWN();                          //定义Delegating
    AdapterPowerMgr( PUNKNOWN pUnknownOuter);
    ~AdapterPowerMgr();
};

其实PortClass提供的几个MINI端口驱动我们在创建我们的适配器端口驱动时,都是以这种方式实现:

  • WaveCyclic

    class WaveCyclic:
       public IMiniportWaveCyclic,
       public CUnknown
    {
    public:
      ////
      DECLARE_STD_UNKNOWN();                          //定义Delegating
      WaveCyclic( PUNKNOWN pUnknownOuter); 
      ~WaveCyclic();
    }
    
  • WaveStream

class WaveStream:
     public IMiniportWaveCyclicStream,
     public IDmaChannel,
     public CUnknown
{
public:
    ///
    DECLARE_STD_UNKNOWN();                         //定义Delegating
    WaveStream( PUNKNOWN pUnknownOuter);
    ~WaveStream();
  • Topology
class Topology:
    public IMiniportTopology,
    public CUnknown
{

public:
    /////
    DECLARE_STD_UNKNOWN();                     //定义Delegating
    Topology( PUNKNOWN pUnknownOuter); 
    ~Topology();

0 篇笔记 写笔记

COM 接口描述语言IDL
COM规范在IDL接口描述语言(OSF的DCE规范)的基础上,通过扩展形成了COM接口的描述语言。接口描述语言提供了一种不依赖于任何语言的接口的描述方法,因此,可成为组件程序和客户程序之间的共同语言。COM规范使用的IDL不仅可用于定义COM接口,同时还定义了一些常用数据类型,也可描述自定义的数据......
CUnknown和INonDelegatingUnknown
CUnknown继承于INonDelegatingUnknown,并且CUnknown是所有COM的基类。class CUnknown : public INonDelegatingUnknown而INonDelegatingUnknown是一个虚基结构体。INonDelegatingUnkn......
IUnknown
与CUnKnow相类似的是IUnknown,其定义如下:#undef INTERFACE#define INTERFACE IUnknownDECLARE_INTERFACE(IUnknown){ STDMETHOD_(NTSTATUS,QueryInterface) ( ......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!