一、通过CLSID
- IBaseFilter *pF = 0;
- HRESULT hr = CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER,
- IID_IBaseFilter, reinterpret_cast<void**>(&pF));
二、通过系统枚举器
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
- IID_ICreateDevEnum, (void **)&pSysDevEnum);
- if (FAILED(hr))
- {
- return hr;
- }
- IEnumMoniker *pEnumCat = NULL;
- hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, &pEnumCat, 0);
- if (hr == S_OK)
- {
- IMoniker *pMoniker = NULL;
- ULONG cFetched;
- while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
- {
- IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
- if (SUCCEEDED(hr))
- {
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- IBaseFilter *pFilter;
- hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
- (void**)&pFilter);
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- pEnumCat->Release();
- }
- pSysDevEnum->Release();
三、通过Filter Mapper
- IFilterMapper2 *pMapper = NULL;
- IEnumMoniker *pEnum = NULL;
- hr = CoCreateInstance(CLSID_FilterMapper2,
- NULL, CLSCTX_INPROC, IID_IFilterMapper2,
- (void **) &pMapper);
- GUID arrayInTypes[2];
- arrayInTypes[0] = MEDIATYPE_Video;
- arrayInTypes[1] = MEDIASUBTYPE_dvsd;
- hr = pMapper->EnumMatchingFilters(
- &pEnum,
- 0, // Reserved.
- TRUE, // Use exact match?
- MERIT_DO_NOT_USE+1, // Minimum merit.
- TRUE, // At least one input pin?
- 1, // Number of major type/subtype pairs for input.
- arrayInTypes, // Array of major type/subtype pairs for input.
- NULL, // Input medium.
- NULL, // Input pin category.
- FALSE, // Must be a renderer?
- TRUE, // At least one output pin?
- 0, // Number of major type/subtype pairs for output.
- NULL, // Array of major type/subtype pairs for output.
- NULL, // Output medium.
- NULL); // Output pin category.
- IMoniker *pMoniker;
- ULONG cFetched;
- while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK)
- {
- IPropertyBag *pPropBag = NULL;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
- if (SUCCEEDED(hr))
- {
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- VariantClear(&varName);
- IBaseFilter *pFilter;
- hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- pMapper->Release();
- pEnum->Release();
第一种方法是最直接的,也最简单,不过当不清楚CLSID的时候,就不得不用后面两种方法。
第二种方法和第三中方法都是使用枚举器枚举Filter,通过匹配Filter的属性来得到Filter,它们不同之处在于:第二种通过确定的种类获得枚举器,第三种通过媒体类型获得枚举器。获得枚举器以后的步骤是相同的。
这三种方法最常用的是第二种。
版权声明:本文为博主原创文章,未经博主允许不得转载。