使用C而不是C ++的Media Foundation [英] Media Foundation using C instead of C++
问题描述
我正在学习使用C而不是C ++从Microsoft网站上显示的示例代码中使用Media Foundation API。示例代码如下所示。
I am learning to use the Media Foundation API from sample code shown in Microsoft website using C instead of C++. The sample code is shown below.
HRESULT CreateVideoCaptureDevice(IMFMediaSource **ppSource)
{
*ppSource = NULL;
UINT32 count = 0;
IMFAttributes *pConfig = NULL;
IMFActivate **ppDevices = NULL;
// Create an attribute store to hold the search criteria.
HRESULT hr = MFCreateAttributes(&pConfig, 1);
// Request video capture devices.
if (SUCCEEDED(hr))
{
hr = pConfig->SetGUID(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
);
}
// Enumerate the devices,
if (SUCCEEDED(hr))
{
hr = MFEnumDeviceSources(pConfig, &ppDevices, &count);
}
// Create a media source for the first device in the list.
if (SUCCEEDED(hr))
{
if (count > 0)
{
hr = ppDevices[0]->ActivateObject(IID_PPV_ARGS(ppSource));
}
else
{
hr = MF_E_NOT_FOUND;
}
}
for (DWORD i = 0; i < count; i++)
{
ppDevices[i]->Release();
}
CoTaskMemFree(ppDevices);
return hr;
}
当我尝试构建示例代码时,总是会出现以下错误:
When I tried to build the sample code, I always get the following error:
错误C2039: ActivateObject:不是 IMFActivate的成员
错误C2039: Release:不是 IMFActivate的成员b $ b错误C2039:'SetGUID':不是'IMFAttributes'的成员
error C2039: 'ActivateObject': is not a member of 'IMFActivate' error C2039: 'Release': is not a member of 'IMFActivate' error C2039: 'SetGUID': is not a member of 'IMFAttributes'
我浏览了IMFActivate和IMFAttributes的定义(在mfidl.h中),我注意到它具有C风格的界面。
I explored the definition of IMFActivate and IMFAttributes (in mfidl.h) and I notice it have a C style interface.
我可以知道是否有人可以显示如何使用该接口的示例吗?
May I know if anyone can show an example of how to use the interface ?
推荐答案
您应该使用虚拟方法表指针使用定义为 C样式的COM接口:
You should be using COM interfaces defined "C style", using virtual method table pointer:
IMFActivate* pMfActivate = ...
IMFMediaSource* pMfMediaSource;
pMfActivate->lpVtbl->ActivateObject(
pMfActivate, &IID_IMFMediaSource, (IUnknown**) &pMfMediaSource);
其中C ++风格是
IMFActivate* pMfActivate = ...
IMFMediaSource* pMfMediaSource;
pMfActivate->ActivateObject(
__uuidof(IMFMediaSource), (IUnknown**) &pMfMediaSource);
这篇关于使用C而不是C ++的Media Foundation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!