directX枚举系统设备类 分类: DirectX 2014-09-20 08:30 491人阅读 评论(0) 收藏
void CSysEnumDlg::DisplayFullCategorySet(void)
{
USES_CONVERSION;
HRESULT hr;
IEnumMoniker *pEmCat = 0;
ICreateDevEnum *pCreateDevEnum = NULL;
int nClasses=0;
// Create an enumerator
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (void**)&pCreateDevEnum);
ASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return;
// Use the meta-category that contains a list of all categories.
// This emulates the behavior of GraphEdit.
hr = pCreateDevEnum->CreateClassEnumerator(
CLSID_ActiveMovieCategories, &pEmCat, 0);
ASSERT(SUCCEEDED(hr));
if(hr == S_OK)
{
IMoniker *pMCat;
ULONG cFetched;
// Enumerate over every category
while(hr = pEmCat->Next(1, &pMCat, &cFetched),
hr == S_OK)
{
IPropertyBag *pPropBag;
// Associate moniker with a file
hr = pMCat->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if(SUCCEEDED(hr))
{
VARIANT varCatClsid;
varCatClsid.vt = VT_BSTR;
// Read CLSID string from property bag
hr = pPropBag->Read(L"CLSID", &varCatClsid, 0);
if(SUCCEEDED(hr))
{
CLSID clsidCat;//枚举所有的设备类
if(CLSIDFromString(varCatClsid.bstrVal, &clsidCat) == S_OK)
{
// Use the guid if we can't get the name
WCHAR *wszCatName;
TCHAR szCatDesc[MAX_PATH];
VARIANT varCatName;
varCatName.vt = VT_BSTR;
// Read filter name
hr = pPropBag->Read(L"FriendlyName", &varCatName, 0);
if(SUCCEEDED(hr))
wszCatName = varCatName.bstrVal;
else
wszCatName = varCatClsid.bstrVal;
#ifndef UNICODE
WideCharToMultiByte(
CP_ACP, 0, wszCatName, -1,
szCatDesc, sizeof(szCatDesc), 0, 0);
#else
lstrcpy(szCatDesc, W2T(wszCatName));
#endif
if(SUCCEEDED(hr))
SysFreeString(varCatName.bstrVal);
// Add category name and CLSID to list box
AddFilterCategory(szCatDesc, &clsidCat);
nClasses++;
}
SysFreeString(varCatClsid.bstrVal);
}
pPropBag->Release();
}
else
{
break;
}
pMCat->Release();
} // for loop
pEmCat->Release();
}
pCreateDevEnum->Release();
// Update listbox title with number of classes
SetNumClasses(nClasses);
}
{
USES_CONVERSION;
HRESULT hr;
IEnumMoniker *pEmCat = 0;
ICreateDevEnum *pCreateDevEnum = NULL;
int nClasses=0;
// Create an enumerator
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (void**)&pCreateDevEnum);
ASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return;
// Use the meta-category that contains a list of all categories.
// This emulates the behavior of GraphEdit.
hr = pCreateDevEnum->CreateClassEnumerator(
CLSID_ActiveMovieCategories, &pEmCat, 0);
ASSERT(SUCCEEDED(hr));
if(hr == S_OK)
{
IMoniker *pMCat;
ULONG cFetched;
// Enumerate over every category
while(hr = pEmCat->Next(1, &pMCat, &cFetched),
hr == S_OK)
{
IPropertyBag *pPropBag;
// Associate moniker with a file
hr = pMCat->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if(SUCCEEDED(hr))
{
VARIANT varCatClsid;
varCatClsid.vt = VT_BSTR;
// Read CLSID string from property bag
hr = pPropBag->Read(L"CLSID", &varCatClsid, 0);
if(SUCCEEDED(hr))
{
CLSID clsidCat;//枚举所有的设备类
if(CLSIDFromString(varCatClsid.bstrVal, &clsidCat) == S_OK)
{
// Use the guid if we can't get the name
WCHAR *wszCatName;
TCHAR szCatDesc[MAX_PATH];
VARIANT varCatName;
varCatName.vt = VT_BSTR;
// Read filter name
hr = pPropBag->Read(L"FriendlyName", &varCatName, 0);
if(SUCCEEDED(hr))
wszCatName = varCatName.bstrVal;
else
wszCatName = varCatClsid.bstrVal;
#ifndef UNICODE
WideCharToMultiByte(
CP_ACP, 0, wszCatName, -1,
szCatDesc, sizeof(szCatDesc), 0, 0);
#else
lstrcpy(szCatDesc, W2T(wszCatName));
#endif
if(SUCCEEDED(hr))
SysFreeString(varCatName.bstrVal);
// Add category name and CLSID to list box
AddFilterCategory(szCatDesc, &clsidCat);
nClasses++;
}
SysFreeString(varCatClsid.bstrVal);
}
pPropBag->Release();
}
else
{
break;
}
pMCat->Release();
} // for loop
pEmCat->Release();
}
pCreateDevEnum->Release();
// Update listbox title with number of classes
SetNumClasses(nClasses);
}
版权声明:本文为博主原创文章,未经博主允许不得转载。