如何用ATL重写下面的函数?
HRESULT EnumerateVideoInputFilters(void** gottaFilter)
{
// Once again, code stolen from the DX9 SDK.
// Create the System Device Enumerator.
ICreateDevEnum *pSysDevEnum = NULL;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
(void **)&pSysDevEnum);
if (FAILED(hr))
{
return hr;
}
// Obtain a class enumerator for the audio input category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
&pEnumCat, 0);
if (hr == S_OK)
{
// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
if (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
// Bind the first moniker to an object.
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropBag);
if (SUCCEEDED(hr))
{
// To retrieve the filter's friendly name,
// do the following:
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
wprintf(L"Selecting Audio Input Device: %s\n",
varName.bstrVal);
}
VariantClear(&varName);
// To create an instance of the filter,
// do the following:
// Remember to release gottaFilter later.
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
gottaFilter);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
return hr;
}
HRESULT EnumerateVideoInputFilters(void** gottaFilter)
{
// Once again, code stolen from the DX9 SDK.
// Create the System Device Enumerator.
ICreateDevEnum *pSysDevEnum = NULL;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
(void **)&pSysDevEnum);
if (FAILED(hr))
{
return hr;
}
// Obtain a class enumerator for the audio input category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
&pEnumCat, 0);
if (hr == S_OK)
{
// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
if (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
// Bind the first moniker to an object.
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropBag);
if (SUCCEEDED(hr))
{
// To retrieve the filter's friendly name,
// do the following:
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
wprintf(L"Selecting Audio Input Device: %s\n",
varName.bstrVal);
}
VariantClear(&varName);
// To create an instance of the filter,
// do the following:
// Remember to release gottaFilter later.
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
gottaFilter);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
return hr;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般想法是,您使用
CComPtr
和其他类似的东西,例如CComBSTR
、CComVariant
、CComQIPtr
::
变为 您的代码更小、更干净 - 您不需要为每个指针调用
Release()
,因此您可以通过提前返回来减少嵌套。General idea is that you use
CComPtr
and other similar things likeCComBSTR
,CComVariant
,CComQIPtr
:becomes:
This makes your code smaller and cleaner - you don't need to call
Release()
for each pointer and thus you can reduce nesting by returning early.