本文整理汇总了C++中IEnumMoniker::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IEnumMoniker::Release方法的具体用法?C++ IEnumMoniker::Release怎么用?C++ IEnumMoniker::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumMoniker
的用法示例。
在下文中一共展示了IEnumMoniker::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindCaptureDevice
HRESULT VideoCapture::FindCaptureDevice(const wchar_t* deviceName, IBaseFilter** ppSrcFilter)
{
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
return hr;
// Obtain a class enumerator for the video input devices category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK) {
// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropBag);
if (SUCCEEDED(hr)) {
// To retrieve the filter's friendly name
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr)) {
if (wcscmp(deviceName, varName.bstrVal) == 0) {
m_DeviceName = varName.bstrVal;
VariantClear(&varName);
IBaseFilter* pFilter;
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
(void**)&pFilter);
if (SUCCEEDED(hr)) {
*ppSrcFilter = pFilter;
(*ppSrcFilter)->AddRef();
pFilter->Release();
}
pPropBag->Release();
pMoniker->Release();
pEnumCat->Release();
pSysDevEnum->Release();
return hr;
}
}
VariantClear(&varName);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
else {
pSysDevEnum->Release();
return hr;
}
pSysDevEnum->Release();
return -1;
}
示例2: CoInitializeEx
// Basics
Audio::Audio(void)
{
logger.addline("Trying to find analong input devices.", debug);
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr))
{
IEnumMoniker *pEnum;
logger.addline("Analong input device(s) has been detected.", info);
hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
if (SUCCEEDED(hr))
{
logger.addline("Have found one or more video input devices", success);
LogDeviceInformation(pEnum);
pEnum->Release();
}
else { logger.addline("No video input device(s) have been detected.", info); }
hr = EnumerateDevices(CLSID_AudioInputDeviceCategory, &pEnum);
logger.addline("Finding out all audio input devices", debug);
if (SUCCEEDED(hr))
{
LogDeviceInformation(pEnum);
pEnum->Release();
}
else { logger.addline("No audio input device(s) have been detected.", info); }
CoUninitialize();
}
else{ logger.addline("Have found no analong input devices", debug); }
logger.addline("All devices as of the start of the program have been detected.", info);
}
示例3: getCaptureDevice
bool MIPDirectShowCapture::getCaptureDevice(int deviceNumber)
{
ICreateDevEnum *pDevEnum = 0;
IEnumMoniker *pEnum = 0;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)(&pDevEnum));
if (HR_FAILED(hr))
{
setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATEDEVICEENUMERATOR);
return false;
}
hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);
if (HR_FAILED(hr))
{
pDevEnum->Release();
setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCAPTUREENUMERATOR);
return false;
}
if (pEnum == 0)
{
pDevEnum->Release();
setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTFINDCAPTUREDEVICE);
return false;
}
IMoniker *pMoniker = NULL;
while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
{
if (deviceNumber == 0)
{
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_pCaptDevice);
pMoniker->Release();
if (HR_SUCCEEDED(hr))
{
pEnum->Release();
pDevEnum->Release();
return true;
}
else
{
m_pCaptDevice = 0;
pEnum->Release();
pDevEnum->Release();
setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTBINDCAPTUREDEVICE);
return false;
}
}
else
deviceNumber--;
}
pEnum->Release();
pDevEnum->Release();
setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTFINDCAPTUREDEVICE);
return false;
}
示例4: IsExcelThere
BOOL IsExcelThere()
{
IRunningObjectTable *pRot = NULL;
::GetRunningObjectTable(0, &pRot);
IEnumMoniker *pEnum = NULL;
pRot->EnumRunning(&pEnum);
IMoniker* pMon[1] = { NULL };
ULONG fetched = 0;
BOOL found = FALSE;
while (pEnum->Next(1, pMon, &fetched) == 0)
{
IUnknown *pUnknown;
pRot->GetObject(pMon[0], &pUnknown);
IUnknown *pWorkbook;
if (SUCCEEDED(pUnknown->QueryInterface(DIID__Workbook, (void **) &pWorkbook)))
{
found = TRUE;
pWorkbook->Release();
break;
}
pUnknown->Release();
}
if (pRot != NULL)
pRot->Release();
if (pEnum != NULL)
pEnum->Release();
return found;
}
示例5: updateEndpoints
void DirectShowAudioEndpointControl::updateEndpoints()
{
IMalloc *oleMalloc = 0;
if (m_deviceEnumerator && CoGetMalloc(1, &oleMalloc) == S_OK) {
IEnumMoniker *monikers = 0;
if (m_deviceEnumerator->CreateClassEnumerator(
CLSID_AudioRendererCategory, &monikers, 0) == S_OK) {
for (IMoniker *moniker = 0; monikers->Next(1, &moniker, 0) == S_OK; moniker->Release()) {
OLECHAR *string = 0;
if (moniker->GetDisplayName(m_bindContext, 0, &string) == S_OK) {
QString deviceId = QString::fromWCharArray(string);
oleMalloc->Free(string);
moniker->AddRef();
m_devices.insert(deviceId, moniker);
if (m_defaultEndpoint.isEmpty()
|| deviceId.endsWith(QLatin1String("Default DirectSound Device"))) {
m_defaultEndpoint = deviceId;
}
}
}
monikers->Release();
}
oleMalloc->Release();
}
}
示例6: GetCaptureDevice
/////////////////////////////////////////////////////////////////////////////////////////
// DirectShowキャプチャデバイスの取得と列挙
/////////////////////////////////////////////////////////////////////////////////////////
BOOL GetCaptureDevice(IBaseFilter **ppSrcFilter)
{
HRESULT hResult;
// デバイスを列挙する
ICreateDevEnum *pDevEnum = NULL;
hResult = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **)&pDevEnum);
if (hResult != S_OK)return FALSE;
// 列挙したデバイスの一番目をデバイスとして取得する
IEnumMoniker *pClassEnum = NULL;
hResult = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
if (hResult != S_OK)return FALSE;
// デバイスをフィルタに接続する
ULONG cFetched;
IMoniker *pMoniker = NULL;
if (pClassEnum->Next(1, &pMoniker, &cFetched) == S_OK){
// 最初のモニカをフィルタオブジェクトにバインドする
pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void **)ppSrcFilter);
pMoniker->Release();
}else
return FALSE;
// グラフビルダに追加する
hResult = g_pGraph->AddFilter(g_pSrc, L"Video Capture");
if (hResult != S_OK)return FALSE;
// オブジェクトの片づけ
pClassEnum->Release();
pDevEnum->Release();
return TRUE;
}
示例7: GetCameraNameDX
void FaceTrackNoIR::GetCameraNameDX() {
#if defined(_WIN32)
ui.cameraName->setText("No video-capturing device was found in your system: check if it's connected!");
// Create the System Device Enumerator.
HRESULT hr;
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
{
qDebug() << "GetWDM says: CoCreateInstance Failed!";
return;
}
qDebug() << "GetWDM says: CoCreateInstance succeeded!";
// Obtain a class enumerator for the video compressor category.
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK) {
qDebug() << "GetWDM says: CreateClassEnumerator succeeded!";
IMoniker *pMoniker = NULL;
ULONG cFetched;
if (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr)) {
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal));
qDebug() << "GetWDM says: Moniker found:" << str;
ui.cameraName->setText(str);
}
VariantClear(&varName);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
#else
for (int i = 0; i < 16; i++) {
char buf[128];
sprintf(buf, "/dev/video%d", i);
if (access(buf, R_OK | W_OK) == 0) {
ui.cameraName->setText(QString(buf));
break;
}
}
#endif
}
示例8: temp
QT_BEGIN_NAMESPACE
DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent)
: QVideoDeviceControl(parent)
{
m_session = qobject_cast<DSCameraSession*>(parent);
devices.clear();
descriptions.clear();
CoInitialize(NULL);
ICreateDevEnum* pDevEnum = NULL;
IEnumMoniker* pEnum = NULL;
// Create the System device enumerator
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
reinterpret_cast<void**>(&pDevEnum));
if(SUCCEEDED(hr)) {
// Create the enumerator for the video capture category
hr = pDevEnum->CreateClassEnumerator(
CLSID_VideoInputDeviceCategory, &pEnum, 0);
if (S_OK == hr) {
pEnum->Reset();
// go through and find all video capture devices
IMoniker* pMoniker = NULL;
while(pEnum->Next(1, &pMoniker, NULL) == S_OK) {
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void**)(&pPropBag));
if(FAILED(hr)) {
pMoniker->Release();
continue; // skip this one
}
// Find the description
WCHAR str[120];
VARIANT varName;
varName.vt = VT_BSTR;
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if(SUCCEEDED(hr)) {
wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
QString temp(QString::fromUtf16((unsigned short*)str));
devices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData());
hr = pPropBag->Read(L"Description", &varName, 0);
wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
QString temp2(QString::fromUtf16((unsigned short*)str));
descriptions.append(temp2.toLocal8Bit().constData());
}
pPropBag->Release();
pMoniker->Release();
}
pEnum->Release();
}
pDevEnum->Release();
}
CoUninitialize();
selected = 0;
}
示例9: getDevFilter
// Used (by getDeviceModes) to select a device
// so we can list its properties
static IBaseFilter* getDevFilter(QString devName)
{
IBaseFilter* devFilter = nullptr;
devName = devName.mid(6); // Remove the "video="
IMoniker* m = nullptr;
ICreateDevEnum* devenum = nullptr;
if (CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (void**) &devenum) != S_OK)
return devFilter;
IEnumMoniker* classenum = nullptr;
if (devenum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
(IEnumMoniker**)&classenum, 0) != S_OK)
return devFilter;
while (classenum->Next(1, &m, nullptr) == S_OK)
{
LPMALLOC coMalloc = nullptr;
IBindCtx* bindCtx = nullptr;
LPOLESTR olestr = nullptr;
char* devIdString;
if (CoGetMalloc(1, &coMalloc) != S_OK)
goto fail;
if (CreateBindCtx(0, &bindCtx) != S_OK)
goto fail;
if (m->GetDisplayName(bindCtx, nullptr, &olestr) != S_OK)
goto fail;
devIdString = wcharToUtf8(olestr);
// replace ':' with '_' since FFmpeg uses : to delimitate sources
for (unsigned i = 0; i < strlen(devIdString); i++)
if (devIdString[i] == ':')
devIdString[i] = '_';
if (devName != devIdString)
goto fail;
if (m->BindToObject(0, 0, IID_IBaseFilter, (void**)&devFilter) != S_OK)
goto fail;
fail:
if (olestr && coMalloc)
coMalloc->Free(olestr);
if (bindCtx)
bindCtx->Release();
delete[] devIdString;
m->Release();
}
classenum->Release();
if (!devFilter)
qWarning() << "Could't find the device "<<devName;
return devFilter;
}
示例10: updateDevices
void DSServicePlugin::updateDevices() const
{
m_cameraDevices.clear();
m_cameraDescriptions.clear();
BOOL bFound = TRUE;
CoInitialize(NULL);
ICreateDevEnum* pDevEnum = NULL;
IEnumMoniker* pEnum = NULL;
// Create the System device enumerator
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
reinterpret_cast<void**>(&pDevEnum));
if(SUCCEEDED(hr)) {
// Create the enumerator for the video capture category
hr = pDevEnum->CreateClassEnumerator(
CLSID_VideoInputDeviceCategory, &pEnum, 0);
if (S_OK == hr) {
pEnum->Reset();
// go through and find all video capture devices
IMoniker* pMoniker = NULL;
while(pEnum->Next(1, &pMoniker, NULL) == S_OK) {
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,
(void**)(&pPropBag));
if(FAILED(hr)) {
pMoniker->Release();
continue; // skip this one
}
bFound = TRUE;
// Find the description
WCHAR str[120];
VARIANT varName;
varName.vt = VT_BSTR;
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if(SUCCEEDED(hr)) {
wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
QString temp(QString::fromUtf16((unsigned short*)str));
m_cameraDevices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData());
hr = pPropBag->Read(L"Description", &varName, 0);
wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
QString temp2(QString::fromUtf16((unsigned short*)str));
m_cameraDescriptions.append(temp2);
} else {
qWarning() << "No friendly name";
}
pPropBag->Release();
pMoniker->Release();
}
pEnum->Release();
}
pDevEnum->Release();
}
CoUninitialize();
if (!bFound) {
qWarning() << "No camera devices found";
}
}
示例11: AccessVisualStudio
/** Accesses the correct visual studio instance if possible. */
bool AccessVisualStudio(CComPtr<EnvDTE::_DTE>& OutDTE, const FString& InSolutionPath, const TArray<FVSAccessorModule::VisualStudioLocation>& InLocations)
{
bool bSuccess = false;
// Open the Running Object Table (ROT)
IRunningObjectTable* RunningObjectTable;
if (SUCCEEDED(GetRunningObjectTable(0, &RunningObjectTable)) &&
RunningObjectTable)
{
IEnumMoniker* MonikersTable;
RunningObjectTable->EnumRunning(&MonikersTable);
MonikersTable->Reset();
// Look for all visual studio instances in the ROT
IMoniker* CurrentMoniker;
while (!bSuccess && MonikersTable->Next(1, &CurrentMoniker, NULL) == S_OK)
{
IBindCtx* BindContext;
LPOLESTR OutName;
CComPtr<IUnknown> ComObject;
if (SUCCEEDED(CreateBindCtx(0, &BindContext)) &&
SUCCEEDED(CurrentMoniker->GetDisplayName(BindContext, NULL, &OutName)) &&
IsVisualStudioMoniker(FString(OutName), InLocations) &&
SUCCEEDED(RunningObjectTable->GetObject(CurrentMoniker, &ComObject)))
{
CComPtr<EnvDTE::_DTE> TempDTE;
TempDTE = ComObject;
// Get the solution path for this instance
// If it equals the solution we would have opened above in RunVisualStudio(), we'll take that
CComPtr<EnvDTE::_Solution> Solution;
LPOLESTR OutPath;
if (SUCCEEDED(TempDTE->get_Solution(&Solution)) &&
SUCCEEDED(Solution->get_FullName(&OutPath)))
{
FString Filename(OutPath);
FPaths::NormalizeFilename(Filename);
if( Filename == InSolutionPath )
{
OutDTE = TempDTE;
bSuccess = true;
}
}
}
BindContext->Release();
CurrentMoniker->Release();
}
MonikersTable->Release();
RunningObjectTable->Release();
}
return bSuccess;
}
示例12: EnumDevices
//枚举设备
HRESULT CCaptureDevice::EnumDevices( REFCLSID clsidDeviceClass, ENUMCALLBACK pEnumCallBack, LPVOID lp )
{
//创建枚举组件
ICreateDevEnum *pCreateDevEnum;
HRESULT hr;
VARIANT var;
hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum );
if( hr==S_OK )
{
//创建枚举器
IEnumMoniker* pEm;
hr = pCreateDevEnum->CreateClassEnumerator( clsidDeviceClass, &pEm, 0 );
if( hr==S_OK )
{
if( pEm )
{
//复位
pEm->Reset();
//准备顺序找设备
ULONG cFetched;
IMoniker *pM;
BOOL bCancel = false;
int index = 0;
while( !bCancel && (hr = pEm->Next(1, &pM, &cFetched), hr==S_OK) )
{
IPropertyBag *pBag;
hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
if(hr==S_OK)
{
ZeroMemory( &var, sizeof(var) );
var.vt = VT_BSTR;
hr = pBag->Read(L"FriendlyName", &var, NULL);
if(hr==S_OK && var.bstrVal!=0 )
{
if(pEnumCallBack)
hr = pEnumCallBack( index, &var, pM, lp, bCancel );
SysFreeString(var.bstrVal);
}
pBag->Release();
}
pM->Release();
index++;
}
//释放
pEm->Release();
}
}
pCreateDevEnum->Release();
}
return hr;
}
示例13: CreateIFileIsInUse
IFileIsInUse* CreateIFileIsInUse(const string& File)
{
IFileIsInUse *pfiu = nullptr;
IRunningObjectTable *prot;
if (SUCCEEDED(GetRunningObjectTable(0, &prot)))
{
IMoniker *pmkFile;
if (SUCCEEDED(CreateFileMoniker(File.data(), &pmkFile)))
{
IEnumMoniker *penumMk;
if (SUCCEEDED(prot->EnumRunning(&penumMk)))
{
HRESULT hr = E_FAIL;
ULONG celt;
IMoniker *pmk;
while (FAILED(hr) && (penumMk->Next(1, &pmk, &celt) == S_OK))
{
DWORD dwType;
if (SUCCEEDED(pmk->IsSystemMoniker(&dwType)) && dwType == MKSYS_FILEMONIKER)
{
IMoniker *pmkPrefix;
if (SUCCEEDED(pmkFile->CommonPrefixWith(pmk, &pmkPrefix)))
{
if (pmkFile->IsEqual(pmkPrefix) == S_OK)
{
IUnknown *punk;
if (prot->GetObject(pmk, &punk) == S_OK)
{
hr = punk->QueryInterface(
#ifdef __GNUC__
IID_IFileIsInUse, IID_PPV_ARGS_Helper(&pfiu)
#else
IID_PPV_ARGS(&pfiu)
#endif
);
punk->Release();
}
}
pmkPrefix->Release();
}
}
pmk->Release();
}
penumMk->Release();
}
pmkFile->Release();
}
prot->Release();
}
return pfiu;
}
示例14: GetCaptureFilters
HRESULT CaptureGraph::GetCaptureFilters(int *filterCount, CListBox *captureFilterList)
{
HRESULT hr;
int maxFilterCount = *filterCount;
ICreateDevEnum *pSysVideoCaptureEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysVideoCaptureEnum);
if (FAILED(hr))
{
return hr;
}
IBaseFilter *pVideoCapture = NULL;
IEnumMoniker *pEnumMoniker = NULL;
hr = pSysVideoCaptureEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumMoniker, 0);
if (hr == S_OK)
{
IMoniker *pMoniker = NULL;
ULONG fetched;
int filterIndex = 0;
while(pEnumMoniker->Next(1, &pMoniker, &fetched) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if(SUCCEEDED(hr))
{
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if(SUCCEEDED(hr))
{
ASSERT(varName.vt == VT_BSTR);
CString friendlyName(varName.bstrVal);
VariantClear(&varName);
pPropBag->Release();
filterIndex ++;
captureFilterList->AddString(friendlyName);
int currentFilterIndex = captureFilterList->FindStringExact(-1, friendlyName);
captureFilterList->SetItemDataPtr(currentFilterIndex, pMoniker);
if(filterIndex > maxFilterCount)
{
*filterCount = filterIndex;
break;
}
}
}
}
pEnumMoniker->Release();
}
pSysVideoCaptureEnum->Release();
}
示例15: GetCaptureFilter
HRESULT GetCaptureFilter(REFCLSID CLSID_DeviceCategory, LPCTSTR lpFriendlyName, void** ppCapture)
{
ICreateDevEnum *pCreateDevEnum = 0;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC_SERVER
, IID_ICreateDevEnum
, (void**)&pCreateDevEnum);
if (FAILED(hr)) return hr;
IEnumMoniker* pEnumMoniker = 0;
hr = pCreateDevEnum->CreateClassEnumerator(CLSID_DeviceCategory, &pEnumMoniker, 0);
if (FAILED(hr))
{
pCreateDevEnum->Release();
return hr;
}
pEnumMoniker->Reset();
BOOL bFound = FALSE;
IMoniker* pMoniker = NULL;
while ((pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK )&& (!bFound))
{
IPropertyBag *pBag = NULL;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
if (SUCCEEDED(hr))
{
VARIANT var = { 0 };
var.vt = VT_BSTR;
hr = pBag->Read(_T("FriendlyName"), &var, NULL);
if (SUCCEEDED(hr))
{
if (!_tcscmp(var.bstrVal, lpFriendlyName))
{
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)ppCapture);
pMoniker->AddRef();
bFound = TRUE;
}
pBag->Release();
}
}
pMoniker->Release();
}//end while
pEnumMoniker->Release();
pCreateDevEnum->Release();
if (*ppCapture == NULL) return E_FAIL;
if (FAILED(hr)) return hr;
return bFound ? S_OK : S_FALSE;
}