DirectShow 枚举设备

void CCaremaDlg::OnButton1() 
{
::CoInitialize(NULL);
// IID myroupName = CLSID_SystemDeviceEnum;
IID myroupName = CLSID_LegacyAmFilterCategory;
IBaseFilter* pFilter = this->FindFilterByClsId(myroupName,"Video Renderer");
int i=0;
}


IBaseFilter* CCaremaDlg::FindFilterByClsId(IID Typeid, CString comName)
{
ICreateDevEnum* pAllDevSource = NULL;
IBaseFilter* pFilter = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,(void**)&pAllDevSource);
if(FAILED(hr)){
MessageBox("Faild!");
}
MessageBox("Success!");
//找出了系统设备
IEnumMoniker* pEnumMoniker = NULL;
ULONG dsize = 0;
hr = pAllDevSource->CreateClassEnumerator(Typeid,&pEnumMoniker,0);
if( hr != S_OK ){
MessageBox("IEnumMoniker Faild!");
}
MessageBox("IEnumMoniker Success!");
IMoniker* pMoniker = NULL;
while( pEnumMoniker->Next(1,&pMoniker,&dsize)==S_OK )
{
IPropertyBag* pProperty = NULL;
if( SUCCEEDED(pMoniker->BindToStorage(NULL,NULL,IID_IPropertyBag,(void**)&pProperty)) )
{
VARIANT DevName;
VariantInit(&DevName);
DevName.vt = VT_BSTR;
pProperty->Read( L"Friendlyname", &DevName, 0 );
CString str(DevName.bstrVal);
VariantClear(&DevName);
MessageBox(str);
if( str == comName )
{
hr = pMoniker->BindToObject(NULL,NULL,IID_IBaseFilter,(void**)&pFilter);
break;
}
}
pProperty->Release();
pMoniker->Release();
}
pEnumMoniker->Release();
return pFilter;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值