iextensionunit类_示例扩展单元插件 DLL - Windows drivers | Microsoft Docs

本文提供了一个CExtension类的示例,该类基于CNodeControl并实现IKsNodeControl和IExtensionUnit接口,用于扩展KS属性集的COM API。代码示例展示了如何处理NodeId和KsControl,以及如何实现IExtensionUnit的相关方法。
摘要由CSDN通过智能技术生成

示例扩展单元 DLLSample extension unit plug-in DLL

06/19/2020

本文内容

本主题包含用于在 KS 属性集的顶层公开 COM API 的扩展单元插件 DLL 的示例代码。This topic contains sample code for an Extension Unit plug-in DLL that exposes a COM API on top of a KS property set.

此示例定义了一个名为 CExtension 的类,该类派生自 CNodeControl。The sample defines a class called CExtension, which derives from CNodeControl. 稍后还提供了 CNodeControl 类的实现。The implementation of the CNodeControl class is also provided later. CNodeControl 派生自 Microsoft 提供的 IKsNodeControl 接口,该接口是在 Vidcap 中定义的。CNodeControl derives from the Microsoft-supplied IKsNodeControl interface, which is defined in Vidcap.h.

Vidcap.ax 使用 IKsNodeControl 来通知扩展节点 ID 的插件,并为其提供 IKsControl 的实例。Vidcap.ax uses IKsNodeControl to inform the plug-in of the extension node ID and provide it with an instance of IKsControl. 具体而言,该插件通过对 CExtension 的调用来接收此信息 ::p _ : :p CExtension 和 _ KsControl。Specifically, the plug-in receives this information through calls to CExtension::put_NodeId and CExtension::put_KsControl. 可以在本主题的 CNodeControl 中找到这些方法的可能实现。You can find possible implementations of these methods later in this topic for the parent class CNodeControl.

Vidcap 通过2月 2005 directx Sdk出现在夏季 2004 directx sdk 中。Vidcap.h appears in the Summer 2004 DirectX SDK through the February 2005 DirectX SDK. 安装这些包时,必须安装其他内容才能获取 Vidcap。When installing these packages, you must install the Extras to obtain Vidcap.h.

在 Windows Vista 和更高版本中, Vidcap 作为 Microsoft Windows SDK 的一部分包含。In Windows Vista and later releases, Vidcap.h is included as part of the Microsoft Windows SDK.

在类头文件中包含以下代码,任意命名为 Xuproxy:Include the following code in the class header file, arbitrarily named Xuproxy.h:

#include

#include

#include

#include

DEFINE_GUID(CLSID_ExtensionUnit, 0xzzzzzzzz, 0xzzzz, 0xzzzz, 0xzz, 0xzz, 0xzz, 0xzz, 0xzz, 0xzz, 0xzz, 0xzz);

class CNodeControl :

public IKsNodeControl

{

public:

STDMETHOD(put_NodeId) (DWORD dwNodeId);

STDMETHOD(put_KsControl) (PVOID pKsControl);

DWORD m_dwNodeId;

CComPtr m_pKsControl;

};

class CExtension :

public IExtensionUnit,

public CComObjectRootEx,

public CComCoClass,

public CNodeControl

{

public:

CExtension();

STDMETHOD(FinalConstruct)();

BEGIN_COM_MAP(CExtension)

COM_INTERFACE_ENTRY(IKsNodeControl)

COM_INTERFACE_ENTRY(IExtensionUnit)

END_COM_MAP()

DECLARE_PROTECT_FINAL_CONSTRUCT()

DECLARE_NO_REGISTRY()

DECLARE_ONLY_AGGREGATABLE(CExtension)

// IExtensionUnit

public:

STDMETHOD (get_Info)(

ULONG ulSize,

BYTE pInfo[]);

STDMETHOD (get_InfoSize)(

ULONG *pulSize);

STDMETHOD (get_PropertySize)(

ULONG PropertyId,

ULONG *pulSize);

STDMETHOD (get_Property)(

ULONG PropertyId,

ULONG ulSize,

BYTE pValue[]);

STDMETHOD (put_Property)(

ULONG PropertyId,

ULONG ulSize,

BYTE pValue[]);

STDMETHOD (get_PropertyRange)(

ULONG PropertyId,

ULONG ulSize,

BYTE pMin[],

BYTE pMax[],

BYTE pSteppingDelta[],

BYTE pDefault[]);

};

#define STATIC_PROPSETID_VIDCAP_EXTENSION_UNIT \

0xXXXXXXXX,0xXXXX,0xXXXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX

DEFINE_GUIDSTRUCT("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", \

PROPSETID_VIDCAP_EXTENSION_UNIT);

#define PROPSETID_VIDCAP_EXTENSION_UNIT \

DEFINE_GUIDNAMED(PROPSETID_VIDCAP_EXTENSION_UNIT)

在 CNodeControl 中实现 IKsNodeControl 中的两个虚拟方法。Implement the two virtual methods from IKsNodeControl in CNodeControl. 然后,这些方法由 CExtension 类的实例继承。These methods are then inherited by instances of the CExtension class.

以下代码位于任意名为 Xuproxy 的源文件中:The following code is in a source file arbitrarily named Xuproxy.cpp:

STDMETHODIMP

CNodeControl::put_NodeId(

DWORD dwNodeId)

{

m_dwNodeId = dwNodeId;

return S_OK;

}

STDMETHODIMP

CNodeControl::put_KsControl(

PVOID pKsControl)

{

HRESULT hr = S_OK;

IKsControl *pIKsControl;

if (!pKsControl) return E_POINTER;

pIKsControl = (IKsControl *) pKsControl;

if (m_pKsControl) m_pKsControl.Release();

hr = pIKsControl->QueryInterface(__uuidof(IKsControl),

(void **) &m_pKsControl);

return hr;

}

还在同一 Xuproxy 文件中包含 CExtension 的方法实现:Also include implementations of CExtension's methods in the same Xuproxy.cpp file:

CExtension::CExtension()

{

m_pKsControl = NULL;

}

STDMETHODIMP

CExtension::FinalConstruct()

{

if (m_pOuterUnknown == NULL ) return E_FAIL;

return S_OK;

}

STDMETHODIMP

CExtension::get_InfoSize(

ULONG *pulSize)

{

HRESULT hr = S_OK;

ULONG ulBytesReturned;

KSP_NODE ExtensionProp;

if (!pulSize) return E_POINTER;

ExtensionProp.Property.Set = PROPSETID_VIDCAP_EXTENSION_UNIT;

ExtensionProp.Property.Id = KSPROPERTY_EXTENSION_UNIT_INFO;

ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET |

KSPROPERTY_TYPE_TOPOLOGY;

ExtensionProp.NodeId = m_dwNodeId;

hr = m_pKsControl->KsProperty(

(PKSPROPERTY) &ExtensionProp,

sizeof(ExtensionProp),

NULL,

0,

&ulBytesReturned);

if (hr == HRESULT_FROM_WIN32(ERROR_MORE_DATA))

{

*pulSize = ulBytesReturned;

hr = S_OK;

}

return hr;

}

STDMETHODIMP

CExtension::get_Info(

ULONG ulSize,

BYTE pInfo[])

{

HRESULT hr = S_OK;

KSP_NODE ExtensionProp;

ULONG ulBytesReturned;

ExtensionProp.Property.Set = PROPSETID_VIDCAP_EXTENSION_UNIT;

ExtensionProp.Property.Id = KSPROPERTY_EXTENSION_UNIT_INFO;

ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET |

KSPROPERTY_TYPE_TOPOLOGY;

ExtensionProp.NodeId = m_dwNodeId;

hr = m_pKsControl->KsProperty(

(PKSPROPERTY) &ExtensionProp,

sizeof(ExtensionProp),

(PVOID) pInfo,

ulSize,

&ulBytesReturned);

return hr;

}

STDMETHODIMP

CExtension::get_PropertySize(

ULONG PropertyId,

ULONG *pulSize)

{

HRESULT hr = S_OK;

ULONG ulBytesReturned;

KSP_NODE ExtensionProp;

if (!pulSize) return E_POINTER;

ExtensionProp.Property.Set = PROPSETID_VIDCAP_EXTENSION_UNIT;

ExtensionProp.Property.Id = PropertyId;

ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET |

KSPROPERTY_TYPE_TOPOLOGY;

ExtensionProp.NodeId = m_dwNodeId;

hr = m_pKsControl->KsProperty(

(PKSPROPERTY) &ExtensionProp,

sizeof(ExtensionProp),

NULL,

0,

&ulBytesReturned);

if (hr == HRESULT_FROM_WIN32(ERROR_MORE_DATA))

{

*pulSize = ulBytesReturned;

hr = S_OK;

}

return hr;

}

STDMETHODIMP

CExtension::get_Property(

ULONG PropertyId,

ULONG ulSize,

BYTE pValue[])

{

HRESULT hr = S_OK;

KSP_NODE ExtensionProp;

ULONG ulBytesReturned;

ExtensionProp.Property.Set = PROPSETID_VIDCAP_EXTENSION_UNIT;

ExtensionProp.Property.Id = PropertyId;

ExtensionProp.Property.Flags = KSPROPERTY_TYPE_GET |

KSPROPERTY_TYPE_TOPOLOGY;

ExtensionProp.NodeId = m_dwNodeId;

hr = m_pKsControl->KsProperty(

(PKSPROPERTY) &ExtensionProp,

sizeof(ExtensionProp),

(PVOID) pValue,

ulSize,

&ulBytesReturned);

return hr;

}

STDMETHODIMP

CExtension::put_Property(

ULONG PropertyId,

ULONG ulSize,

BYTE pValue[])

{

HRESULT hr = S_OK;

KSP_NODE ExtensionProp;

ULONG ulBytesReturned;

ExtensionProp.Property.Set = PROPSETID_VIDCAP_EXTENSION_UNIT;

ExtensionProp.Property.Id = PropertyId;

ExtensionProp.Property.Flags = KSPROPERTY_TYPE_SET |

KSPROPERTY_TYPE_TOPOLOGY;

ExtensionProp.NodeId = m_dwNodeId;

hr = m_pKsControl->KsProperty(

(PKSPROPERTY) &ExtensionProp,

sizeof(ExtensionProp),

(PVOID) pValue,

ulSize,

&ulBytesReturned);

return hr;

}

STDMETHODIMP

CExtension::get_PropertyRange(

ULONG PropertyId,

ULONG ulSize,

BYTE pMin[ ],

BYTE pMax[ ],

BYTE pSteppingDelta[ ],

BYTE pDefault[ ])

{

// IHV may add code here, current stub just returns S_OK

HRESULT hr = S_OK;

return hr;

}

CExtension::CExtension()

{

m_pKsControl = NULL;

}

STDMETHODIMP

CExtension::FinalConstruct()

{

if (m_pOuterUnknown == NULL) return E_FAIL;

return S_OK;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值