简体   繁体   English

Media Foundation使用C而不是C ++

[英]Media Foundation using C instead of C++

I am learning to use the Media Foundation API from sample code shown in Microsoft website using C instead of C++. 我正在学习使用C代替C ++从Microsoft网站上显示的示例代码中使用Media Foundation API。 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: 当我尝试构建示例代码时,我总是会收到以下错误:

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' 错误C2039:'ActivateObject':不是'IMFActivate'的成员错误C2039:'Release':不是'IMFActivate'的成员错误C2039:'SetGUID':不是'IMFAttributes'的成员

I explored the definition of IMFActivate and IMFAttributes (in mfidl.h) and I notice it have a C style interface. 我探讨了IMFActivate和IMFAttributes的定义(在mfidl.h中),我注意到它有一个C风格的界面。

May I know if anyone can show an example of how to use the interface ? 我可以知道是否有人可以展示如何使用该界面的示例?

You should be using COM interfaces defined "C style", using virtual method table pointer: 您应该使用定义为“C style”的COM接口,使用虚方法表指针:

IMFActivate* pMfActivate = ...
IMFMediaSource* pMfMediaSource;
pMfActivate->lpVtbl->ActivateObject(
    pMfActivate, &IID_IMFMediaSource, (IUnknown**) &pMfMediaSource);

where C++ style is C ++风格的地方

IMFActivate* pMfActivate = ...
IMFMediaSource* pMfMediaSource;
pMfActivate->ActivateObject(
    __uuidof(IMFMediaSource), (IUnknown**) &pMfMediaSource);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM