directshow 對系統中不可預知性硬體提供了良好的支援,其方法是使用系統列舉,系統列舉的一般過程如下所示:
(1)使用cocreateinstance函式建立系統列舉器組建物件(clsid為clsid_systemdeviceenum),並獲得icreatedevenum介面;
(2)使用介面方法icreatedevenum::createclassenumerator為指定的filter註冊型別目錄建立乙個列舉器,並獲得ienummoniker介面;
(3)使用ienummoniker介面方法列舉指定型別目錄下所有裝置標識(devicemoniker);
(4)呼叫imoniker::bindtostorage之後,可以訪問裝置標識的屬性集,比如得到display name、friendly name等;
(5)呼叫imoniker::bindtoobject可以將裝置標識生成乙個directshow filter,隨後呼叫ifiltergraph::addfilter,並將之加入到filtergraph中就可以參與工作了。
下面是這個過程的**:
//建立乙個系統列舉組建
hresult hr;
icreatedevenum* psysdevenum = null;
hr = cocreateinstance(clsid_systemdeviceenum, null, clsctx_inproc_server, iid_icreatedevenum, (void**)&psysdevenum);
if(failed(hr))
// 指定列舉的型別目錄,獲得ienummoniker介面
ienummoniker* penumcat = null;
hr = psysdevenum->createclassenumerator(clsid_videoinputdevicecategory, &penumcat, 0);
if(hr == s_ok)
variantclear(&varname);
// create filter instance
ibasefilter* pfilter;
hr = pmoniker->bindtoobject(null, null, iid_ibasefilter, (void**)&pfilter);
// now add the filter to the graph
// remember to release pfilter later
ppropbag->release();
}pmoniker->release();
}penumcat->release;
}psysdevenum->release();
列舉系統裝置
方法一 include include include include include include pragma comment lib,setupapi.lib define bufsize 1024 define sm serverr 289 intmain enumerate throug...
C 實現Windows系統裝置列舉
1.列舉系統裝置 hdevinfo hdevinfo sp devinfo data deviceinfodata dword dwdevid 得到所有裝置 hdevinfo hdevinfo setupdigetclassdevs null,0,0,digcf present digcf allc...
列舉裝置棧
hello.h pragma once include define countarray array sizeof array sizeof array 0 typedef struct device extension device extension,pdevice extension ifd...