Example #1
0
int CCaptureVideo::EnumDevices(CArray<CString, CString>& arList)
{
	int nCount = 0;
	//枚举视频扑捉设备
	ICreateDevEnum *pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum);
	
	if (hr != NOERROR)return -1;
	
	CComPtr<IEnumMoniker> pEm;
	
	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0);
	
	if (hr != NOERROR)return -1;
	
	pEm->Reset();
	
	ULONG cFetched;
	
	IMoniker *pM;
	
	while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
	{
		IPropertyBag *pBag;

		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);

		if(SUCCEEDED(hr)) 
		{
			VARIANT var;

			var.vt = VT_BSTR;

			hr = pBag->Read(L"FriendlyName", &var, NULL);

			if (hr == NOERROR) 
			{
				char szStr[2048];

				nCount++;

				WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, szStr, 2048, NULL, NULL);
				
				arList.Add( CString(szStr) );
				
				SysFreeString(var.bstrVal);
				
				pM->AddRef();

			}

			pBag->Release();
		}

		pM->Release();
	}

	return nCount;
}
// @pymethod |PyIOleObject|SetMoniker|Description of SetMoniker.
PyObject *PyIOleObject::SetMoniker(PyObject *self, PyObject *args)
{
	IOleObject *pIOO = GetI(self);
	if ( pIOO == NULL )
		return NULL;
	// @pyparm int|dwWhichMoniker||Description for dwWhichMoniker
	// @pyparm <o PyIMoniker>|pmk||Description for pmk
	PyObject *obpmk;
	DWORD dwWhichMoniker;
	IMoniker * pmk;
	if ( !PyArg_ParseTuple(args, "iO:SetMoniker", &dwWhichMoniker, &obpmk) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obpmk, IID_IMoniker, (void **)&pmk, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIOO->SetMoniker( dwWhichMoniker, pmk );
	if (pmk) pmk->Release();
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return OleSetOleError(hr);
	Py_INCREF(Py_None);
	return Py_None;

}
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();
    }
}
Example #4
0
bool CHtmlDialog::DoModal()
{
	if (!m_hInstMSHTML)
		return false;

	// First get the proc ShowHTMLDialog
	typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGFN(HWND hwndParent, IMoniker *pmk, VARIANT *pvarArgIn, WCHAR* pchOptions, VARIANT *pvArgOut);
	SHOWHTMLDIALOGFN* pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)::GetProcAddress(m_hInstMSHTML, TEXT("ShowHTMLDialog"));
//j	typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGEXFN(HWND hwndParent, IMoniker *pmk, DWORD dwDialogFlags, VARIANT *pvarArgIn, WCHAR* pchOptions, VARIANT *pvArgOut);
//j	SHOWHTMLDIALOGEXFN* pfnShowHTMLDialog = (SHOWHTMLDIALOGEXFN*)::GetProcAddress(m_hInstMSHTML, TEXT("ShowHTMLDialogEx"));
	if (!pfnShowHTMLDialog)
		return false;
	
	// Now create a URL Moniker
	IMoniker* pmk = NULL;
	::CreateURLMoniker(NULL, CComBSTR(m_strURL), &pmk);
	if (!pmk)
		return false;
	
	// Now show the HTML Dialog
	HWND hWndFocus = ::GetFocus();
	CComVariant varArgs = m_strArguments;
	HWND hWndParent = (::IsWindow(m_hWndParent) && ::IsWindowVisible(m_hWndParent) ? m_hWndParent : NULL);
	HRESULT hr = pfnShowHTMLDialog(hWndParent, pmk, &varArgs, CComBSTR(m_strOptions), &m_varReturn);
//j	CComVariant vstrOptions = m_strOptions;
//j	HRESULT hr = pfnShowHTMLDialog(hWndParent, pmk, HTMLDLG_MODAL, &varArgs, vstrOptions, &m_varReturn);
	pmk->Release();
	::SetFocus(hWndFocus);

	return (FAILED(hr) ? false : true);
}
Example #5
0
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;        
}
/////////////////////////////////////////////////////////////////////////////////////////
// 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;
}
Example #7
0
void CJs2nCtrl::OnSetClientSite() 
{
	// TODO: Add your specialized code here and/or call the base class
	LPOLECLIENTSITE pClientSite = GetClientSite();

	if (pClientSite != NULL)
	{
		// Obtain URL from container moniker.
		IMoniker*	ppmk;
		LPOLESTR	pszDisplayName;

		if (SUCCEEDED(pClientSite->GetMoniker( OLEGETMONIKER_TEMPFORUSER,
											   OLEWHICHMK_CONTAINER,
											   &ppmk)))
		{
			if (SUCCEEDED(ppmk->GetDisplayName(NULL, NULL, &pszDisplayName)))
			{
				PString strURL( (WORD *)pszDisplayName );
				PString strPluginsPath = FindPluginsPath();
				m_NativeLogic.Init( strURL, strPluginsPath );
				CoTaskMemFree((LPVOID)pszDisplayName);
			}
		}
	}

	COleControl::OnSetClientSite();
}
Example #8
0
// @pymethod <o PyIMoniker>|PyIMoniker|ComposeWith|Combines the current moniker with another moniker, creating a new composite moniker.
PyObject *PyIMoniker::ComposeWith(PyObject *self, PyObject *args)
{
	// @pyparm <o PyIMoniker>|mkRight||The IMoniker interface on the moniker to compose onto the end of this moniker.
	// @pyparm int|fOnlyIfNotGeneric||If TRUE, the caller requires a non-generic composition, so the operation should proceed only if pmkRight is a moniker class that this moniker can compose with in some way other than forming a generic composite. If FALSE, the method can create a generic composite if necessary.
	PyObject *obmkRight;
	int bOnlyIfNotGeneric;
	if (!PyArg_ParseTuple(args, "Oi:ComposeWith", &obmkRight, &bOnlyIfNotGeneric))
		return NULL;

	IMoniker *pMy = GetI(self);
	if (pMy==NULL) return NULL;

	IMoniker *pmkRight;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obmkRight, IID_IMoniker, (void **)&pmkRight, FALSE))
		return NULL;

	IMoniker *pResult = NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pMy->ComposeWith(pmkRight, bOnlyIfNotGeneric, &pResult);
	pmkRight->Release();
	PY_INTERFACE_POSTCALL;
	if (S_OK!=hr) // S_OK only acceptable
		return PyCom_BuildPyException(hr, pMy, IID_IMoniker);
	return PyCom_PyObjectFromIUnknown(pResult, IID_IMoniker, FALSE );
}
Example #9
0
void CMFCBindCntrItem::LoadFromMoniker(LPUNKNOWN pUnk, OLECHAR* szwName)
{
	HRESULT hr;
	// Ask the system for a URL Moniker
	IMoniker* pIMoniker;
	hr = CreateURLMoniker(NULL, (LPWSTR)szwName, &pIMoniker);
	if ( SUCCEEDED(hr) )
	{
		// Get the IPersistMoniker interface
		IPersistMoniker* pPMk;
		hr = pUnk->QueryInterface(
								IID_IPersistMoniker,
								(void **)&pPMk);
		if ( SUCCEEDED(hr) )
		{
				// note: do not register our BSC when calling IPM::Load directly
			IBindCtx *pBCtx;
			hr = CreateBindCtx(0, &pBCtx);
			if ( SUCCEEDED(hr) )
			{
				// Call Load on the IPersistMoniker
				hr = pPMk->Load(FALSE, pIMoniker, pBCtx, STGM_READ);
					pBCtx->Release();
			}
			pPMk->Release();
		}
		pIMoniker->Release( );
	}
}
Example #10
0
HRESULT CaptureDevices::GetAudioDevices(vector<wstring> *audioDevices)
{
	if (!enumMonikerAudio)
		return E_FAIL;

	IMoniker *pMoniker = NULL;
	wstring name;

	while (enumMonikerAudio->Next(1, &pMoniker, NULL) == S_OK)
	{
		IPropertyBag *pPropBag;
		HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
		if (FAILED(hr))
		{
			pMoniker->Release();
			continue;  
		} 

		VARIANT var;
		VariantInit(&var);

		hr = pPropBag->Read(L"FriendlyName", &var, 0);
		if (SUCCEEDED(hr))
		{
			name = var.bstrVal;
			VariantClear(&var); 
		}

		pPropBag->Release();
		pMoniker->Release();

		if (!name.empty())
			audioDevices->push_back(name);
	}
}
Example #11
0
bool VideoCapture::BindFilter(int deviceId, IBaseFilter **pFilter)
{
	if (deviceId < 0)
		return false;
	
    // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
			  IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR)
		return false;

    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
								&pEm, 0);
    if (hr != NOERROR) 
		return false;

    pEm->Reset();
    IMoniker *pM;

	for (int i=0; i<=deviceId; i++)
		pEm->Next(1, &pM, NULL);

	IPropertyBag *pBag;
	hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
	pM->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
	pM->Release();

	return true;
}
Example #12
0
bool CDirectShowFilterFinder::FindFilter(const GUID *pInTypes,int InTypeCount,
	const GUID *pOutTypes,int OutTypeCount,DWORD Merit)
{
	// フィルタを検索する
	bool bRet = false;
	IFilterMapper2 *pMapper=NULL;
	HRESULT hr=::CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC, IID_IFilterMapper2, (void **)&pMapper);

	if (SUCCEEDED(hr)) {
		IEnumMoniker *pEnum=NULL;

		hr = pMapper->EnumMatchingFilters(
			&pEnum,
			0,					// 予約済み
			TRUE,				// 完全一致を使用するか
			Merit,				// 最小のメリット
			TRUE,				// 1 つ以上の入力ピンか?
			InTypeCount,		// 入力のメジャータイプ/サブタイプの対の数
			pInTypes,			// 入力のメジャータイプ/サブタイプの対の配列
			NULL,				// 入力メディア
			NULL,				// 入力ピンのカテゴリ
			FALSE,				// レンダラでなければならないか
			TRUE,				// 1 つ以上の出力ピンか
			OutTypeCount,		// 出力のメジャータイプ/サブタイプの対の数
			pOutTypes,			// 出力のメジャータイプ/サブタイプの対の配列
			NULL,				// 出力メディア
			NULL);				// 出力ピンのカテゴリ
		if (SUCCEEDED(hr)) {
			IMoniker *pMoniker;
			ULONG cFetched;
			while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK) {
				IPropertyBag *pPropBag;
				hr=pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
				if (SUCCEEDED(hr)) {
					VARIANT varName,varID;
					::VariantInit(&varName);
					::VariantInit(&varID);
					hr=pPropBag->Read(L"FriendlyName", &varName, 0);
					if (SUCCEEDED(hr)) {
						hr=pPropBag->Read(L"CLSID", &varID, 0);
						if (SUCCEEDED(hr)) {
							bRet = true;
							CFilterInfo FilterInfo;
							FilterInfo.SetFriendlyName(varName.bstrVal);
							::CLSIDFromString(varID.bstrVal,&FilterInfo.m_clsid);
							m_FilterList.push_back(FilterInfo);
							::SysFreeString(varID.bstrVal);
						}
						SysFreeString(varName.bstrVal);
					}
					pPropBag->Release();
				}
				pMoniker->Release();
			}
			pEnum->Release();
		}
		pMapper->Release();
	}
	return bRet;
}
Example #13
0
/* Wireshark example (with proxy enabled)
    GET /Resources.zip HTTP/1.0
    Accept: *//*
    Request-Range: bytes=2-5
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Host: www.myurl.com
    Pragma: no-cache
    Via: 1.1 myproxy.com:3128 (squid/2.7.STABLE7)
    X-Forwarded-For: 192.168.0.2
    Cache-Control: max-age=259200
    Connection: keep-alive

   Wireshark example (no proxy, direct connection):
    GET /Resources.zip HTTP/1.1
    Accept: *//*
    Request-Range: bytes=2-5
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Host: www.myurl.com
    Connection: Keep-Alive
    Cache-Control: no-cache
*/
void UseWinInet(const WCHAR* URL)
{
    HRESULT hr;

    IBindStatusCallback* ibscb(0);
    ::CBindStatusCallback::Create( &ibscb );
    /*HRESULT uoshr = URLOpenStream( 0, L"http://www.myurl.com/Resources.zip", 0, ibscb );
    ShowMessage( hwnd, "URLOpenStream: " + toString(uoshr) );*/
    IMoniker* FMoniker;
    CreateURLMoniker(0, URL, &FMoniker);

    IBindCtx* FBindCtx;
    CreateAsyncBindCtx(0, ibscb, 0, &FBindCtx);

    hr = IsValidURL(FBindCtx, URL, 0);
    if ( hr != S_OK )
    {
        ShowMessage( 0, "Invalid url" );
    }
   
    IStream* fstream;
    hr = FMoniker->BindToStorage(FBindCtx, 0, IID_IStream, (void**)&fstream);

    if ( (hr != S_OK) && (hr != MK_S_ASYNCHRONOUS) )
    {
        ShowMessage( 0, "error" );
    }
}
Example #14
0
HRESULT AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister) 
{
    IMoniker * pMoniker;
    IRunningObjectTable *pROT;
    if (FAILED(GetRunningObjectTable(0, &pROT))) 
    {
        return E_FAIL;
    }

    WCHAR wsz[128];
    wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph, 
              GetCurrentProcessId());

    HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker);
    if (SUCCEEDED(hr)) 
    {
        // Use the ROTFLAGS_REGISTRATIONKEEPSALIVE to ensure a strong reference
        // to the object.  Using this flag will cause the object to remain
        // registered until it is explicitly revoked with the Revoke() method.
        //
        // Not using this flag means that if GraphEdit remotely connects
        // to this graph and then GraphEdit exits, this object registration 
        // will be deleted, causing future attempts by GraphEdit to fail until
        // this application is restarted or until the graph is registered again.
        hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, 
                            pMoniker, pdwRegister);
        pMoniker->Release();
    }

    pROT->Release();
    return hr;
}
Example #15
0
IHTMLWindow2* CHtmlDialog::DoModeless()
{
	if (!m_hInstMSHTML)
		return false;

	// First get the proc ShowModelessHTMLDialog
	typedef HRESULT STDAPICALLTYPE SHOWMODELESSHTMLDIALOGFN(HWND hwndParent, IMoniker *pmk, VARIANT *pvarArgIn, VARIANT* pvarOptions, IHTMLWindow2 ** ppWindow);
	SHOWMODELESSHTMLDIALOGFN* pfnShowHTMLDialog = (SHOWMODELESSHTMLDIALOGFN*)::GetProcAddress(m_hInstMSHTML, TEXT("ShowModelessHTMLDialog"));
	if (!pfnShowHTMLDialog)
		return false;
	
	// Now create a URL Moniker
	IMoniker* pmk = NULL;
	::CreateURLMoniker(NULL, CComBSTR(m_strURL), &pmk);
	if (!pmk)
		return false;
	
	// Now show the HTML Dialog
	HWND hWndFocus = ::GetFocus();
	CComVariant varArgs = m_strArguments;
	HWND hWndParent = (::IsWindow(m_hWndParent) && ::IsWindowVisible(m_hWndParent) ? m_hWndParent : NULL);
	IHTMLWindow2* pModelessWindow = NULL;
	CComVariant vstrOptions = m_strOptions;
	HRESULT hr = pfnShowHTMLDialog(hWndParent, pmk, &varArgs, &vstrOptions, &pModelessWindow);
	pmk->Release();
	::SetFocus(hWndFocus);

	return pModelessWindow;
}
// Returns the IMoniker* for the given device index. - caller must Release() the object
bool VideoCaptureDirectShow2::createDeviceFilter(int device, IBaseFilter** deviceFilter) {

  IEnumMoniker* enum_moniker = NULL;
  if(!createDeviceMoniker(&enum_moniker)) {
    RX_ERROR("Cannot create IEnumMoniker so also not the device");
    return false;
  }
  
  // Get information from devices
  IMoniker* moniker = NULL;
  int count = 0;
  bool found = false;
  while(enum_moniker->Next(1, &moniker, NULL) == S_OK) {

    if(count == device) {
      HRESULT hr = moniker->BindToObject(0, 0, IID_IBaseFilter, (void**)deviceFilter);
      if(FAILED(hr)) {
        RX_ERROR("Error while trying to bind the device to the IBaseFilter");
        break;
      }
      found = true;
      (*deviceFilter)->AddRef(); // @todo - do we really need this here?
      break;
    }

    ++count;
    moniker->Release();
  }

  safeReleaseDirectShow(&enum_moniker);
  safeReleaseDirectShow(&moniker);
  return true;
}
void Audio::LogDeviceInformation(IEnumMoniker *pEnum)
{
	logger.addline("Starting to record audio or video input devices.", info);
	IMoniker *pMoniker = NULL;

	while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
	{
		logger.addline("Have found a new device", success);
		IPropertyBag *pPropBag;
		HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
		if (FAILED(hr))
		{
			pMoniker->Release();
			continue;
		}

		VARIANT var;
		VariantInit(&var);

		// Get description or friendly name.
		hr = pPropBag->Read(L"Description", &var, 0);
		if (FAILED(hr))
		{
			hr = pPropBag->Read(L"FriendlyName", &var, 0);
		}
		if (SUCCEEDED(hr))
		{
			//printf("%S\n", var.bstrVal);
			logger.addline("Below is the device name.", debug);
			logger.addline(ConvertBSTRToMBS(var.bstrVal), debug);
			VariantClear(&var);
		}

		hr = pPropBag->Write(L"FriendlyName", &var);

		// WaveInID applies only to audio capture devices.
		hr = pPropBag->Read(L"WaveInID", &var, 0);
		if (SUCCEEDED(hr))
		{
			//printf("WaveIn ID: %d\n", var.lVal);
			logger.addline("Below is the WaveIn ID.", debug);
			logger.addline("BLANK FOR NOW! FIX ME LATER", debug);
			VariantClear(&var);
		}

		hr = pPropBag->Read(L"DevicePath", &var, 0);
		if (SUCCEEDED(hr))
		{
			// The device path is not intended for display.
			printf("Device path: %S\n", var.bstrVal);
			logger.addline("Below is the device path.", debug);
			//logger.addline(ConvertBSTRToMBS(var.bstrVal), success);
			VariantClear(&var);
		}

		pPropBag->Release();
		pMoniker->Release();
	}
}
Example #18
0
bool CCaptureVideo::BindFilter(int deviceId, IBaseFilter **pFilter)
{
	if (deviceId < 0) return false;

	// enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
	IID_ICreateDevEnum, (void**)&pCreateDevEnum);

	if (hr != NOERROR) return false;

	CComPtr<IEnumMoniker> pEm;

	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0);

	if (hr != NOERROR) return false;

	pEm->Reset();

	ULONG cFetched;

	IMoniker* pM;

	int index = 0;

	while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK, index <= deviceId)
	{
		IPropertyBag* pBag;

		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);

		if(SUCCEEDED(hr)) 
		{
			VARIANT var;

			var.vt = VT_BSTR;

			hr = pBag->Read(L"FriendlyName", &var, NULL);

			if (hr == NOERROR) 
			{
				if (index == deviceId)
				{
					pM->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
				}
				SysFreeString(var.bstrVal);
			}

			pBag->Release();

		}

		pM->Release();

		index++;
	}
	return true;
}
Example #19
0
QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
    Q_UNUSED(mode)

    QList<QByteArray> devices;
    //enumerate device fullnames through directshow api
    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));

    unsigned long iNumDevs = mode == QAudio::AudioOutput ? waveOutGetNumDevs() : waveInGetNumDevs();
    if (SUCCEEDED(hr)) {
        // Create the enumerator for the audio input/output category
        if (pDevEnum->CreateClassEnumerator(
             mode == QAudio::AudioOutput ? CLSID_AudioRendererCategory : CLSID_AudioInputDeviceCategory,
             &pEnum, 0) == S_OK) {
            pEnum->Reset();
            // go through and find all audio devices
            IMoniker *pMoniker = NULL;
            while (pEnum->Next(1, &pMoniker, NULL) == S_OK) {
                IPropertyBag *pPropBag;
                hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,
                     reinterpret_cast<void **>(&pPropBag));
                if (FAILED(hr)) {
                    pMoniker->Release();
                    continue; // skip this one
                }
                // Find if it is a wave device
                VARIANT var;
                VariantInit(&var);
                hr = pPropBag->Read(mode == QAudio::AudioOutput ? L"WaveOutID" : L"WaveInID", &var, 0);
                if (SUCCEEDED(hr)) {
                    LONG waveID = var.lVal;
                    if (waveID >= 0 && waveID < LONG(iNumDevs)) {
                        VariantClear(&var);
                        // Find the description
                        hr = pPropBag->Read(L"FriendlyName", &var, 0);
                        if (SUCCEEDED(hr)) {
                            QByteArray  device;
                            QDataStream ds(&device, QIODevice::WriteOnly);
                            ds << quint32(waveID) << QString::fromWCharArray(var.bstrVal);
                            devices.append(device);
                        }
                    }
                }

                pPropBag->Release();
                pMoniker->Release();
            }
        }
    }
    CoUninitialize();

    return devices;
}
Example #20
0
int Camera::EnumDevices(PENUMDEVICE pCallback, void* pItem)
{
	int nDevice = 0;
	HRESULT			hr				= S_OK;

	// System device enumerators
	ICreateDevEnum	*pDevEnum		= NULL;
	IEnumMoniker	*pEnum			= NULL;
	IMoniker		*pMoniker		= NULL;

	CoInitialize(NULL);

	// Create system device enumerator
	hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>(&pDevEnum) );
	if (FAILED(hr)) {
		return 0;
	}

	// create enumerator for video capture devices
	hr = pDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEnum, 0 );
	if (SUCCEEDED(hr)) 
	{
		IBindCtx* pbcfull = NULL;

		// Enumerate through the devices and print friendly name
		while ( (pEnum->Next( 1, &pMoniker, NULL ) == S_OK))
		{	
			VARIANT var;
			IPropertyBag *pPropertyBag;
			char szCameraName[200];

			// FrienlyName : The name of the device
			var.vt = VT_BSTR;

			// Bind to IPropertyBag
			pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropertyBag);
			
			// Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx
			hr = pPropertyBag->Read(L"Description", &var, 0);	// "FriendlyName", "DevicePath", "Description"
			if (FAILED(hr))
			{
				pPropertyBag->Read(L"FriendlyName", &var, 0);
			}
			WideCharToMultiByte(CP_ACP, 0, var.bstrVal, -1,szCameraName, sizeof(szCameraName), 0, 0);
			if (pCallback != NULL) {
				(*pCallback)(pItem, szCameraName);
			}
			VariantClear(&var);

			// Release resource
			pPropertyBag->Release();

			nDevice++;

			SAFE_RELEASE( pMoniker );
		}
	}
	return nDevice; // returns count of camera
}
Example #21
0
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
}
Example #22
0
// 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;
}
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;
}
Example #24
0
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";
    }
}
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;
}
Example #26
0
int VideoCapture::EnumDevices()
{
	int id = 0;
	
    // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
								  IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR)  return -1;
	
    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
								&pEm, 0);
    if (hr != NOERROR) 	return -1 ;
    
    pEm->Reset();

    IMoniker *pM;
	nDevices = 0;
    while(hr = pEm->Next(1, &pM, NULL), hr==S_OK)
		nDevices++;
	
	if (nDevices==0) return -1;

	pEm->Reset();

	devices_names = new string[nDevices];
		
	while(hr = pEm->Next(1, &pM, NULL), hr==S_OK)
    {
		IPropertyBag *pBag;
		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		if(SUCCEEDED(hr)) 
		{
			VARIANT var;
			var.vt = VT_BSTR;
			hr = pBag->Read(L"FriendlyName", &var, NULL);
			if (hr == NOERROR) 
			{
				TCHAR str[2048];		

				WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, str, 2048, NULL, NULL);
				devices_names[id] = str;

				id++;

				SysFreeString(var.bstrVal);
			}
			pBag->Release();
		}
		pM->Release();
    }
	return id;
}
/** 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;
}
Example #28
0
//枚举设备
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;
}
Example #29
0
int CCameraDS::CameraName(int nCamID, char* sName, int nBufferSize)
{
	int count = 0;
 	CoInitialize(NULL);

   // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
									IID_ICreateDevEnum, (void**)&pCreateDevEnum);

    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
        &pEm, 0);
    if (hr != NOERROR) return 0;


    pEm->Reset();
    ULONG cFetched;
    IMoniker *pM;
    while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
    {
		if (count == nCamID)
		{
			IPropertyBag *pBag=0;
			hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
			if(SUCCEEDED(hr))
			{
				VARIANT var;
				var.vt = VT_BSTR;
				hr = pBag->Read(L"FriendlyName", &var, NULL); //还有其他属性,像描述信息等等...
	            if(hr == NOERROR)
		        {
			        //获取设备名称			
					WideCharToMultiByte(CP_ACP,0,var.bstrVal,-1,sName, nBufferSize ,"",NULL);

	                SysFreeString(var.bstrVal);				
		        }
			    pBag->Release();
			}
			pM->Release();

			break;
		}
		count++;
    }

	pCreateDevEnum = NULL;
	pEm = NULL;

	return 1;
}
Example #30
0
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();
}