#include <atlbase.h>
#include <DShow.h>
#pragma comment(lib,"Strmiids.lib")
 
CComPtr<IFilterMapper> pMapper;
HRESULT hr=pMapper.CoCreateInstance(CLSID_FilterMapper);
if(FAILED(hr))
{
    _tprintf(L"创建IFilterMapper接口失败\n");
    return 0;
}
 
CComPtr<IEnumRegFilters> pEnumRegFilters;
DWORD dwMerit=0;
hr=pMapper->EnumMatchingFilters(&pEnumRegFilters,dwMerit,FALSE,GUID_NULL,GUID_NULL,FALSE,FALSE,GUID_NULL,GUID_NULL);
if(FAILED(hr))
{
    _tprintf(L"创建IEnumRegFilters接口失败\n");
    return 0;
}
 
int Nums=0;
ULONG cFetched=0;
REGFILTER *pRegFilter=NULL;
while(pEnumRegFilters->Next(1,&pRegFilter,&cFetched)==S_OK)
{
    for(size_t i=0;i<cFetched;i++)
    {
        _tprintf(L"%02d %s\n",++Nums,(pRegFilter+i)->Name);
    }
 
    CoTaskMemFree(pRegFilter);
}
 
pEnumRegFilters.Release();
pMapper.Release();

需要注意的是:

自己开发的Filter如果只是简单的通过AMovieDllRegisterServer2(TRUE)注册,将不会被枚举出来。

 

为了可以被枚举,还需要用IFilterMapper::RegisterFilterFilter信息写入注册表,代码如下:

HRESULT RegisterFilter(BOOL bRegister)
{
    CComPtr<IFilterMapper> pMapper;
    HRESULT hr=pMapper.CoCreateInstance(CLSID_FilterMapper);
    if(FAILED(hr))
    {
        _tprintf(L"创建IFilterMapper接口失败\n");
        return hr;
    }
 
    if(bRegister)
    {
        hr=pMapper->RegisterFilter(CLSID_RotationFilter,L"Rotation Filter",MERIT_NORMAL);
        if(FAILED(hr))
        {
            _tprintf(L"RegisterFilter CLSID_RotationFilter失败\n");
            return hr;
        }
    }
    else
    {
        hr=pMapper->UnregisterFilter(CLSID_RotationFilter);
        if(FAILED(hr))
        {
            _tprintf(L"UnregisterFilter CLSID_RotationFilter失败\n");
            return hr;
        }
    }
 
    pMapper.Release();
    return S_OK;
}
 
STDAPI DllRegisterServer()
{
    HRESULT hr= AMovieDllRegisterServer2(TRUE);
    if (FAILED(hr))
    {
        return hr;
    }
 
    hr=RegisterFilter(TRUE);
    if (FAILED(hr))
    {
        return hr;
    }
 
    return S_OK;
}

本文链接地址: DirectShow.4 枚举Windows Mobile (WinCE) 所有Filter
http://qingfengju.com/index.asp?id=268

分类:嵌入式/电子 查看次数:6985 发布时间:2011-11-21 16:07:46