directX根据设备类GUID查询所属的filter 分类: DirectX 2014-09-20 08:34 501人阅读 评论(0) 收藏

hr = m_pSysDevEnum->CreateClassEnumerator(*clsid, &pEnumCat, 0);
    ASSERT(SUCCEEDED(hr));
    if FAILED(hr)
        return;


    // Enumerate all filters using the category enumerator
    hr = EnumFilters(pEnumCat);


IBaseFilter *buf[20];

HRESULT CSysEnumDlg::EnumFilters(IEnumMoniker *pEnumCat)
{
    HRESULT hr=S_OK;
    IMoniker *pMoniker;
    ULONG cFetched;
    VARIANT varName={0};
    int nFilters=0;
    IBaseFilter * pSrc = NULL;
    // Clear the current filter list
    ClearFilterList();


    // If there are no filters of a requested type, show default string
    if (!pEnumCat)
    {
        m_FilterList.AddString(TEXT("<< No entries >>"));
        SetNumFilters(nFilters);
        return S_FALSE;
    }


    // Enumerate all items associated with the moniker
    while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
    {
        IPropertyBag *pPropBag;
        ASSERT(pMoniker);


        // Associate moniker with a file
        hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
                                    (void **)&pPropBag);
        ASSERT(SUCCEEDED(hr));
        ASSERT(pPropBag);
        if (FAILED(hr))
            continue;


        // Read filter name from property bag
        varName.vt = VT_BSTR;
        hr = pPropBag->Read(L"FriendlyName", &varName, 0);
        if (FAILED(hr))
            continue;


        // Get filter name (converting BSTR name to a CString)
        CString str(varName.bstrVal);

/*

       if(hr == NOERROR)//根据名称检索filter
        {
CString str(varName.bstrVal);


if (str.Find("Virtual Camera",0)!=-1)
{
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
//  Msg(TEXT("Couldn't bind moniker to filter object!  hr=0x%x"), hr);
break;
}
break;
}

}

*/

        SysFreeString(varName.bstrVal);
        
//////////////////////////////////////////
        hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
            AfxMessageBox(_T("err001"),MB_OK,NULL);
buf[nFilters] = pSrc;//保持当前的设备类的所有的filter

/////////////////////////////////////////////
nFilters++;
        // Read filter's CLSID from property bag.  This CLSID string will be
        // converted to a binary CLSID and passed to AddFilter(), which will
        // add the filter's name to the listbox and its CLSID to the listbox
        // item's DataPtr item.  When the user clicks on a filter name in
        // the listbox, we'll read the stored CLSID, convert it to a string,
        // and use it to find the filter's filename in the registry.
        VARIANT varFilterClsid;
        varFilterClsid.vt = VT_BSTR;


        // Read CLSID string from property bag
        hr = pPropBag->Read(L"CLSID", &varFilterClsid, 0);
        if(SUCCEEDED(hr))
        {
            CLSID clsidFilter;


            // Add filter name and CLSID to listbox
            if(CLSIDFromString(varFilterClsid.bstrVal, &clsidFilter) == S_OK)
            {
                AddFilter(str, &clsidFilter);
            }


            SysFreeString(varFilterClsid.bstrVal);
        }
       
        // Cleanup interfaces
        SAFE_RELEASE(pPropBag);
        SAFE_RELEASE(pMoniker);
    }


    // Update count of enumerated filters
    SetNumFilters(nFilters);
    return hr;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-09-20 08:34  毛毛虫的薄刻  阅读(161)  评论(0编辑  收藏  举报