Delphi -- DirectShow枚举设备代码片断

var
  CreateDevEnum:ICreateDevEnum;
  EnumMoniker:IEnumMoniker;
  Moniker:IMoniker;
  PropertyBag:IPropertyBag;
  varName:OleVariant;
  hr:HRESULT;
const
  IID_IPropertyBag: TGUID = '{55272A00-42CB-11CE-8135-00AA004BB851}';
begin
  hr:=CoCreateInstance(CLSID_SystemDeviceEnum,nil,CLSCTX_INPROC_SERVER,IID_ICreateDevEnum,CreateDevEnum);
  Assert(hr=NOERROR);
  hr:=CreateDevEnum.CreateClassEnumerator(AM_KSCATEGORY_CAPTURE,EnumMoniker,0);
  Assert(hr=NOERROR);
  EnumMoniker.Reset;
  while EnumMoniker.Next(1,Moniker,nil)=S_OK do
  begin
    hr:=Moniker.BindToStorage(nil,nil,IID_IPropertyBag,PropertyBag);
    if Failed(hr) then Continue;
    VariantInit(varName);
    hr:=PropertyBag.Read('FriendlyName',varName,nil);
    if Succeeded(hr) then
    begin
      ShowMessage(varName);
      VariantClear(varName); 
    end;
  end;
end;
posted @ 2008-09-27 15:17  Max Woods  阅读(842)  评论(0编辑  收藏  举报