全部博文(282)
分类:
2007-09-20 23:09:52
HRESULT FindFilterInterface( IGraphBuilder *pGraph, // Pointer to the Filter Graph Manager. REFGUID iid, // IID of the interface to retrieve. void **ppUnk) // Receives the interface pointer. { if (!pGraph || !ppUnk) return E_POINTER; HRESULT hr = E_FAIL; IEnumFilters *pEnum = NULL; IBaseFilter *pF = NULL; if (FAILED(pGraph->EnumFilters(&pEnum))) { return E_FAIL; } // Query every filter for the interface. while (S_OK == pEnum->Next(1, &pF, 0)) { hr = pF->QueryInterface(iid, ppUnk); pF->Release(); if (SUCCEEDED(hr)) { break; } } pEnum->Release(); return hr; } |
HRESULT FindPinInterface( IBaseFilter *pFilter, // Pointer to the filter to search. REFGUID iid, // IID of the interface. void **ppUnk) // Receives the interface pointer. { if (!pFilter || !ppUnk) return E_POINTER; HRESULT hr = E_FAIL; IEnumPins *pEnum = 0; if (FAILED(pFilter->EnumPins(&pEnum))) { return E_FAIL; } // Query every pin for the interface. IPin *pPin = 0; while (S_OK == pEnum->Next(1, &pPin, 0)) { hr = pPin->QueryInterface(iid, ppUnk); pPin->Release(); if (SUCCEEDED(hr)) { break; } } pEnum->Release(); return hr; } |
HRESULT FindInterfaceAnywhere( IGraphBuilder *pGraph, REFGUID iid, void **ppUnk) { if (!pGraph || !ppUnk) return E_POINTER; HRESULT hr = E_FAIL; IEnumFilters *pEnum = 0; if (FAILED(pGraph->EnumFilters(&pEnum))) { return E_FAIL; } // Loop through every filter in the graph. IBaseFilter *pF = 0; while (S_OK == pEnum->Next(1, &pF, 0)) { hr = pF->QueryInterface(iid, ppUnk); if (FAILED(hr)) { // The filter does not expose the interface, but maybe // one of its pins does. //调用的是上面的搜索pin的函数 hr = FindPinInterface(pF, iid, ppUnk); } pF->Release(); if (SUCCEEDED(hr)) { break; } } pEnum->Release(); return hr; } |