IUnknown
2022-08-23
41
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();