Exemplo n.º 1
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( );
	}
}
Exemplo n.º 2
0
// @pymethod interface|PyIShellItem|BindToHandler|Creates an instance of one of the item's handlers
PyObject *PyIShellItem::BindToHandler(PyObject *self, PyObject *args)
{
	IShellItem *pISI = GetI(self);
	if ( pISI == NULL )
		return NULL;
	// @pyparm <o PyIBindCtx>|pbc||Used to pass parameters that influence the binding operation, can be None
	// @pyparm <o PyIID>|bhid||GUID that identifies a handler (shell.BHID_*)
	// @pyparm <o PyIID>|riid||The interface to return
	PyObject *obpbc;
	PyObject *obbhid;
	PyObject *obriid;
	IBindCtx *pbc;
	IID bhid;
	IID riid;
	void *pv;
	if ( !PyArg_ParseTuple(args, "OOO:BindToHandler", &obpbc, &obbhid, &obriid) )
		return NULL;
	if (!PyWinObject_AsIID(obbhid, &bhid))
		return NULL;
	if (!PyWinObject_AsIID(obriid, &riid))
		return NULL;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISI->BindToHandler( pbc, bhid, riid, &pv );
	if (pbc) pbc->Release();

	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISI, IID_IShellItem );
	return PyCom_PyObjectFromIUnknown((IUnknown *)pv, riid, FALSE);
}
Exemplo n.º 3
0
// @pymethod |PyIExplorerCommand|Invoke|Description of Invoke.
PyObject *PyIExplorerCommand::Invoke(PyObject *self, PyObject *args)
{
	IExplorerCommand *pIEC = GetI(self);
	if ( pIEC == NULL )
		return NULL;
	// @pyparm <o PyIShellItemArray>|psiItemArray||Description for psiItemArray
	// @pyparm <o PyIBindCtx>|pbc||Description for pbc
	PyObject *obpsiItemArray;
	PyObject *obpbc;
	IShellItemArray *psiItemArray;
	IBindCtx *pbc;
	if ( !PyArg_ParseTuple(args, "OO:Invoke", &obpsiItemArray, &obpbc) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpsiItemArray, IID_IShellItemArray, (void **)&psiItemArray, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIEC->Invoke( psiItemArray, pbc );
	if (psiItemArray) psiItemArray->Release();
	if (pbc) pbc->Release();

	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIEC, IID_IExplorerCommand );
	Py_INCREF(Py_None);
	return Py_None;

}
Exemplo n.º 4
0
// @pymethod |PyIShellItemArray|BindToHandler|Description of BindToHandler.
PyObject *PyIShellItemArray::BindToHandler(PyObject *self, PyObject *args)
{
	IShellItemArray *pISIA = GetI(self);
	if ( pISIA == NULL )
		return NULL;
	// @pyparm <o PyIBindCtx>|pbc||Description for pbc
	// @pyparm <o PyIID>|rbhid||Description for rbhid
	// @pyparm <o PyIID>|riid||Description for riid
	PyObject *obpbc;
	PyObject *obrbhid;
	PyObject *obriid;
	IBindCtx *pbc;
	IID rbhid;
	IID riid;
	void *pvOut;
	if ( !PyArg_ParseTuple(args, "OOO:BindToHandler", &obpbc, &obrbhid, &obriid) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!PyWinObject_AsIID(obrbhid, &rbhid)) bPythonIsHappy = FALSE;
	if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISIA->BindToHandler( pbc, rbhid, riid, &pvOut );
	if (pbc) pbc->Release();

	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pISIA, IID_IShellItemArray );
	return PyCom_PyObjectFromIUnknown((IUnknown *)pvOut, riid, FALSE);
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
/** 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;
}
Exemplo n.º 7
0
// @pymethod <o PyIUnknown>|PyIMoniker|BindToStorage|Retrieves an interface object to the storage that contains the object identified by the moniker.
PyObject *PyIMoniker::BindToStorage(PyObject *self, PyObject *args)
{
	// @pyparm <o PyIBindCtx>|bindCtx||bind context object to be used.
	// @pyparm <o PyIMoniker>|moniker||If the moniker is part of a composite moniker, otherwise None
	// @pyparm <o IID>|iidResult||IID of the result object.
	PyObject *obBindCtx;
	PyObject *obMoniker;
	PyObject *obIID;

	if (!PyArg_ParseTuple(args, "OOO:BindToStorage", &obBindCtx, &obMoniker, &obIID))
		return NULL;

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

	IBindCtx *pBindCtx;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obBindCtx, IID_IBindCtx, (void **)&pBindCtx, FALSE))
		return NULL;
	
	IMoniker *pMonLeft = NULL;
	if (obMoniker!=Py_None) {
		if (!PyCom_InterfaceFromPyInstanceOrObject(obMoniker, IID_IMoniker, (void **)&pMonLeft, FALSE)) {
			PY_INTERFACE_PRECALL;
			pBindCtx->Release();
			PY_INTERFACE_POSTCALL;

			return NULL;
		}
	}
	IID iid;
	if (!PyWinObject_AsIID(obIID, &iid)) {
		PY_INTERFACE_PRECALL;
		pBindCtx->Release();
		if (pMonLeft) pMonLeft->Release();
		PY_INTERFACE_POSTCALL;

		return NULL;
	}

	void *pResult = NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMy->BindToStorage(pBindCtx, pMonLeft, iid, &pResult );
	pBindCtx->Release();
	if (pMonLeft) pMonLeft->Release();
	PY_INTERFACE_POSTCALL;

	if (S_OK!=hr) // S_OK only acceptable
		return PyCom_BuildPyException(hr, pMy, IID_IMoniker);
	return PyCom_PyObjectFromIUnknown((IUnknown *)pResult, iid, FALSE );
}
HRESULT CFLVConverter::CreateVideoCompressor(IBaseFilter** ppFilter)
{
// Video capture category
static WCHAR szMon[] = L"@device:cm:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\msvc";
IBindCtx *pBindCtx;
ULONG chEaten = 0;
IMoniker *pMoniker = 0;
	if(!ppFilter) return E_POINTER;
	*ppFilter = NULL;
	HRESULT hr = CreateBindCtx(0, &pBindCtx);

	hr = MkParseDisplayName(pBindCtx, szMon, &chEaten, &pMoniker);
	pBindCtx->Release();
	if (SUCCEEDED(hr))
	{
		hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**) ppFilter);
		//need not: hr = pGB->AddFilter(ppFilter, L"MSVC1");
		pMoniker->Release();
	}
	return hr;
}
Exemplo n.º 9
0
// @pymethod string|PyIMoniker|GetDisplayName|Gets the display name , which is a user-readable representation of this moniker.
PyObject *PyIMoniker::GetDisplayName(PyObject *self, PyObject *args)
{
	// @pyparm <o PyIBindCtx>|bindCtx||bind context object to be used.
	// @pyparm <o PyIMoniker>|moniker||If the moniker is part of a composite moniker, otherwise None
	PyObject *obBindCtx;
	PyObject *obMoniker;

	if (!PyArg_ParseTuple(args, "OO:GetDisplayName", &obBindCtx, &obMoniker))
		return NULL;

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

	IBindCtx *pBindCtx;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obBindCtx, IID_IBindCtx, (void **)&pBindCtx, FALSE))
		return NULL;
	
	IMoniker *pMonLeft = NULL;
	if (obMoniker!=Py_None) {
		if (!PyCom_InterfaceFromPyInstanceOrObject(obMoniker, IID_IMoniker, (void **)&pMonLeft, FALSE)) {
			PY_INTERFACE_PRECALL;
			pBindCtx->Release();
			PY_INTERFACE_POSTCALL;
			return NULL;
		}
	}
	LPOLESTR result;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMy->GetDisplayName(pBindCtx, pMonLeft, &result );
	pBindCtx->Release();
	if (pMonLeft) pMonLeft->Release();
	PY_INTERFACE_POSTCALL;
	if (S_OK!=hr) // S_OK only acceptable
		return PyCom_BuildPyException(hr, pMy, IID_IMoniker);
	PyObject *obResult = PyWinObject_FromWCHAR(result);
	CoTaskMemFree(result);
	return obResult;
}
Exemplo n.º 10
0
QVector<QPair<QString,QString>> DirectShow::getDeviceList()
{
    IMoniker* m = nullptr;
    QVector<QPair<QString,QString>> devices;

    ICreateDevEnum* devenum = nullptr;
    if (CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER,
                             IID_ICreateDevEnum, (void**) &devenum) != S_OK)
        return devices;

    IEnumMoniker* classenum = nullptr;
    if (devenum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
                                (IEnumMoniker**)&classenum, 0) != S_OK)
        return devices;

    while (classenum->Next(1, &m, nullptr) == S_OK)
    {
        VARIANT var;
        IPropertyBag* bag = nullptr;
        LPMALLOC coMalloc = nullptr;
        IBindCtx* bindCtx = nullptr;
        LPOLESTR olestr = nullptr;
        char *devIdString=nullptr, *devHumanName=nullptr;

        if (CoGetMalloc(1, &coMalloc) != S_OK)
            goto fail;
        if (CreateBindCtx(0, &bindCtx) != S_OK)
            goto fail;

        // Get an uuid for the device that we can pass to ffmpeg directly
        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] = '_';

        // Get a human friendly name/description
        if (m->BindToStorage(nullptr, nullptr, IID_IPropertyBag, (void**)&bag) != S_OK)
            goto fail;

        var.vt = VT_BSTR;
        if (bag->Read(L"FriendlyName", &var, nullptr) != S_OK)
            goto fail;
        devHumanName = wcharToUtf8(var.bstrVal);

        devices += {QString("video=")+devIdString, devHumanName};

fail:
        if (olestr && coMalloc)
            coMalloc->Free(olestr);
        if (bindCtx)
            bindCtx->Release();
        delete[] devIdString;
        delete[] devHumanName;
        if (bag)
            bag->Release();
        m->Release();
    }
    classenum->Release();

    return devices;
}
static GstCaps *
gst_dshowaudiosrc_get_caps (GstBaseSrc * basesrc)
{
  HRESULT hres = S_OK;
  IBindCtx *lpbc = NULL;
  IMoniker *audiom = NULL;
  DWORD dwEaten;
  GstDshowAudioSrc *src = GST_DSHOWAUDIOSRC (basesrc);
  gunichar2 *unidevice = NULL;

  if (src->device) {
    g_free (src->device);
    src->device = NULL;
  }

  src->device =
      gst_dshow_getdevice_from_devicename (&CLSID_AudioInputDeviceCategory,
      &src->device_name);
  if (!src->device) {
    GST_ERROR ("No audio device found.");
    return NULL;
  }
  unidevice =
      g_utf8_to_utf16 (src->device, strlen (src->device), NULL, NULL, NULL);

  if (!src->audio_cap_filter) {
    hres = CreateBindCtx (0, &lpbc);
    if (SUCCEEDED (hres)) {
      hres =
          MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &audiom);
      if (SUCCEEDED (hres)) {
        hres = audiom->BindToObject (lpbc, NULL, IID_IBaseFilter,
            (LPVOID *) & src->audio_cap_filter);
        audiom->Release ();
      }
      lpbc->Release ();
    }
  }

  if (src->audio_cap_filter && !src->caps) {
    /* get the capture pins supported types */
    IPin *capture_pin = NULL;
    IEnumPins *enumpins = NULL;
    HRESULT hres;

    hres = src->audio_cap_filter->EnumPins (&enumpins);
    if (SUCCEEDED (hres)) {
      while (enumpins->Next (1, &capture_pin, NULL) == S_OK) {
        IKsPropertySet *pKs = NULL;

        hres =
            capture_pin->QueryInterface (IID_IKsPropertySet, (LPVOID *) & pKs);
        if (SUCCEEDED (hres) && pKs) {
          DWORD cbReturned;
          GUID pin_category;
          RPC_STATUS rpcstatus;

          hres =
              pKs->Get (AMPROPSETID_Pin,
              AMPROPERTY_PIN_CATEGORY, NULL, 0, &pin_category, sizeof (GUID),
              &cbReturned);

          /* we only want capture pins */
          if (UuidCompare (&pin_category, (UUID *) & PIN_CATEGORY_CAPTURE,
                  &rpcstatus) == 0) {
            IAMStreamConfig *streamcaps = NULL;

            if (SUCCEEDED (capture_pin->QueryInterface (IID_IAMStreamConfig,
                        (LPVOID *) & streamcaps))) {
              src->caps =
                  gst_dshowaudiosrc_getcaps_from_streamcaps (src, capture_pin,
                  streamcaps);
              streamcaps->Release ();
            }
          }
          pKs->Release ();
        }
        capture_pin->Release ();
      }
      enumpins->Release ();
    }
  }

  if (unidevice) {
    g_free (unidevice);
  }

  if (src->caps) {
    return gst_caps_ref (src->caps);
  }

  return NULL;
}
Exemplo n.º 12
0
static GstCaps *
gst_dshowvideosrc_get_caps (GstBaseSrc * basesrc, GstCaps *filter)
{
    HRESULT hres = S_OK;
    IBindCtx *lpbc = NULL;
    IMoniker *videom;
    DWORD dwEaten;
    GstDshowVideoSrc *src = GST_DSHOWVIDEOSRC (basesrc);
    gunichar2 *unidevice = NULL;

    if (src->caps) {
        return gst_caps_ref (src->caps);
    }

    if (!src->device) {
        src->device =
            gst_dshow_getdevice_from_devicename (&CLSID_VideoInputDeviceCategory,
                    &src->device_name);
        if (!src->device) {
            GST_ERROR ("No video device found.");
            return NULL;
        }
    }

    unidevice =
        g_utf8_to_utf16 (src->device, strlen (src->device), NULL, NULL, NULL);

    if (!src->video_cap_filter) {
        hres = CreateBindCtx (0, &lpbc);
        if (SUCCEEDED (hres)) {
            hres =
                MkParseDisplayName (lpbc, (LPCOLESTR) unidevice, &dwEaten, &videom);
            if (SUCCEEDED (hres)) {
                hres = videom->BindToObject (lpbc, NULL, IID_IBaseFilter,
                                             (LPVOID *) & src->video_cap_filter);
                videom->Release ();
            }
            lpbc->Release ();
        }
    }

    if (!src->caps) {
        src->caps = gst_caps_new_empty ();
    }

    if (src->video_cap_filter && gst_caps_is_empty (src->caps)) {
        /* get the capture pins supported types */
        IPin *capture_pin = NULL;
        IEnumPins *enumpins = NULL;
        HRESULT hres;

        hres = src->video_cap_filter->EnumPins (&enumpins);
        if (SUCCEEDED (hres)) {
            while (enumpins->Next (1, &capture_pin, NULL) == S_OK) {
                IKsPropertySet *pKs = NULL;
                hres =
                    capture_pin->QueryInterface (IID_IKsPropertySet, (LPVOID *) & pKs);
                if (SUCCEEDED (hres) && pKs) {
                    DWORD cbReturned;
                    GUID pin_category;
                    RPC_STATUS rpcstatus;

                    hres =
                        pKs->Get (AMPROPSETID_Pin,
                                  AMPROPERTY_PIN_CATEGORY, NULL, 0, &pin_category, sizeof (GUID),
                                  &cbReturned);

                    /* we only want capture pins */
                    if (UuidCompare (&pin_category, (UUID *) & PIN_CATEGORY_CAPTURE,
                                     &rpcstatus) == 0) {
                        {
                            GstCaps *caps =
                                gst_dshowvideosrc_getcaps_from_streamcaps (src, capture_pin);
                            if (caps) {
                                gst_caps_append (src->caps, caps);
                            } else {
                                caps = gst_dshowvideosrc_getcaps_from_enum_mediatypes (src, capture_pin);
                                if (caps)
                                    gst_caps_append (src->caps, caps);
                            }
                        }
                    }
                    pKs->Release ();
                }
                capture_pin->Release ();
            }
            enumpins->Release ();
        }
    }

    if (unidevice) {
        g_free (unidevice);
    }

    if (src->caps) {
        if (filter) {
            return gst_caps_intersect_full (filter, src->caps,
                                            GST_CAPS_INTERSECT_FIRST);
        } else {
            return gst_caps_ref (src->caps);
        }
    }

    return NULL;
}
Exemplo n.º 13
0
Arquivo: SITE.CPP Projeto: 0anion0/IBN
/*
 * CSite::Load
 *
 * Purpose:
 *  Loads the path provided using IPersistMoniker or IPersistFile. If no path
 *	was provided it simply does an InitNew
 *
 * Parameters:
 *  pchPath - The path
 *
 * Return Value:
 */
HRESULT CSite::Load(LPCTSTR pchPath)
{
    HRESULT   hr = S_OK;

    if ( pchPath != NULL && *pchPath != 0)
    {
        USES_CONVERSION;
        LPWSTR szwName = T2W(const_cast<LPTSTR>(pchPath));

        // Path has been provided so check should we use IPersistMoniker or IPersistFile?
        if (memcmp(pchPath, _T("file:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("http:"), 5 * sizeof(TCHAR)) == 0 ||
                memcmp(pchPath, _T("https:"), 5 * sizeof(TCHAR)) == 0)
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);

            // 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 = m_pObj->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();
                    }
                    ReleaseInterface(pPMk);
                }
                ReleaseInterface( pIMoniker );
            }
        }
        else if ( m_pFR->IsFilterIn() )
        {
            IPersistStreamInit* pPStm = NULL;
            LPSTREAM pFilteredStream = NULL;
            DWORD dwFlags = 0;

//			dwFlags = ((CCEditApp*) AfxGetApp())->GetOptions().GetFilterFlags();
//			dwFlags |= dwFilterMultiByteStream; // loading an ANSI Stream

            hr = m_pObj->QueryInterface(
                     IID_IPersistStreamInit,
                     (void **)&pPStm);

            if ( SUCCEEDED(hr) )
            {
                if (SUCCEEDED(hr = HrFilterIn(pchPath, &pFilteredStream, dwFlags)))
                {
                    hr = pPStm->Load(pFilteredStream);

                    ReleaseInterface(pFilteredStream);
                    ReleaseInterface(pPStm);
                }
            }
        }
        else
        {
//		    OLECHAR  szwName[256];
//			MultiByteToWideChar(CP_ACP, 0, pchPath, -1, szwName, 256);
            IPersistFile*  pPFile;
            hr = m_pObj->QueryInterface(
                     IID_IPersistFile,
                     (void **) &pPFile);
            if ( SUCCEEDED(hr) )
            {
                // Call Load on the IPersistFile
                hr = pPFile->Load((LPWSTR)szwName, 0);
                ReleaseInterface(pPFile);
            }
        }
    }
    else
    {
        // No path provided so just do an InitNew on the Stream
        IPersistStreamInit* pPStm;
        hr = m_pObj->QueryInterface(
                 IID_IPersistStreamInit,
                 (void **)&pPStm);
        if ( SUCCEEDED(hr) )
        {
            hr = pPStm->InitNew();
            ReleaseInterface(pPStm);
        }
    }

    return hr;
}
Exemplo n.º 14
0
HRESULT FindCaptureDevice(IBaseFilter ** ppSrcFilter)
{
	HRESULT hr;
	IBaseFilter * pSrc = NULL;
	IMoniker *pMoniker = NULL;
	ULONG cFetched;

	if (!ppSrcFilter)
		return E_POINTER;

	// Create the system device enumerator
	ICreateDevEnum *pDevEnum = NULL;

	hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
		IID_ICreateDevEnum, (void **)&pDevEnum);
	if (FAILED(hr))
	{
		return hr;
	}

	// Create an enumerator for the video capture devices
	IEnumMoniker *pClassEnum = NULL;

	hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
	if (FAILED(hr))
	{
		return hr;
	}

	// If there are no enumerators for the requested type, then 
	// CreateClassEnumerator will succeed, but pClassEnum will be NULL.
	if (pClassEnum == NULL)
	{
		return E_FAIL;
	}

	// Use the first video capture device on the device list.
	// Note that if the Next() call succeeds but there are no monikers,
	// it will return S_FALSE (which is not a failure).  Therefore, we
	// check that the return code is S_OK instead of using SUCCEEDED() macro.
	if (S_OK == (pClassEnum->Next(1, &pMoniker, &cFetched)))
	{
		IBindCtx *pbc = NULL;

		CreateBindCtx(0, &pbc);
		// Bind Moniker to a filter object
		hr = pMoniker->BindToObject(pbc, 0, IID_IBaseFilter, (void**)&pSrc);
		pbc->Release();
		if (FAILED(hr))
		{
			return hr;
		}
	}
	else
	{
		return E_FAIL;
	}

	// Copy the found filter pointer to the output parameter.
	// Do NOT Release() the reference, since it will still be used
	// by the calling function.
	*ppSrcFilter = pSrc;

	return hr;
}
/** Accesses the correct visual studio instance if possible. */
EAccessVisualStudioResult AccessVisualStudioViaDTE(TComPtr<EnvDTE::_DTE>& OutDTE, const FString& InSolutionPath, const TArray<FVisualStudioSourceCodeAccessor::VisualStudioLocation>& InLocations)
{
	EAccessVisualStudioResult AccessResult = EAccessVisualStudioResult::VSInstanceIsNotOpen;

	// Open the Running Object Table (ROT)
	IRunningObjectTable* RunningObjectTable;
	if(SUCCEEDED(GetRunningObjectTable(0, &RunningObjectTable)) && RunningObjectTable)
	{
		IEnumMoniker* MonikersTable;
		if(SUCCEEDED(RunningObjectTable->EnumRunning(&MonikersTable)))
		{
			MonikersTable->Reset();

			// Look for all visual studio instances in the ROT
			IMoniker* CurrentMoniker;
			while(AccessResult != EAccessVisualStudioResult::VSInstanceIsOpen && MonikersTable->Next(1, &CurrentMoniker, NULL) == S_OK)
			{
				IBindCtx* BindContext;
				LPOLESTR OutName;
				if(SUCCEEDED(CreateBindCtx(0, &BindContext)) && SUCCEEDED(CurrentMoniker->GetDisplayName(BindContext, NULL, &OutName)))
				{
					if(IsVisualStudioDTEMoniker(FString(OutName), InLocations))
					{
						TComPtr<IUnknown> ComObject;
						if(SUCCEEDED(RunningObjectTable->GetObject(CurrentMoniker, &ComObject)))
						{
							TComPtr<EnvDTE::_DTE> TempDTE;
							if (SUCCEEDED(TempDTE.FromQueryInterface(__uuidof(EnvDTE::_DTE), ComObject)))
							{
								// Get the solution path for this instance
								// If it equals the solution we would have opened above in RunVisualStudio(), we'll take that
								TComPtr<EnvDTE::_Solution> Solution;
								BSTR OutPath = nullptr;
								if (SUCCEEDED(TempDTE->get_Solution(&Solution)) &&
									SUCCEEDED(Solution->get_FullName(&OutPath)))
								{
									FString Filename(OutPath);
									FPaths::NormalizeFilename(Filename);

									if (Filename == InSolutionPath)
									{
										OutDTE = TempDTE;
										AccessResult = EAccessVisualStudioResult::VSInstanceIsOpen;
									}

									SysFreeString(OutPath);
								}
								else
								{
									UE_LOG(LogVSAccessor, Warning, TEXT("Visual Studio is open but could not be queried - it may be blocked by a modal operation"));
									AccessResult = EAccessVisualStudioResult::VSInstanceIsBlocked;
								}
							}
							else
							{
								UE_LOG(LogVSAccessor, Warning, TEXT("Could not get DTE interface from returned Visual Studio instance"));
								AccessResult = EAccessVisualStudioResult::VSInstanceIsBlocked;
							}
						}
						else
						{
							UE_LOG(LogVSAccessor, Warning, TEXT("Couldn't get Visual Studio COM object"));
							AccessResult = EAccessVisualStudioResult::VSInstanceUnknown;
						}
					}
				}
				else
				{
					UE_LOG(LogVSAccessor, Warning, TEXT("Couldn't get display name"));
					AccessResult = EAccessVisualStudioResult::VSInstanceUnknown;
				}
				BindContext->Release();
				CurrentMoniker->Release();
			}
			MonikersTable->Release();
		}
		else
		{
			UE_LOG(LogVSAccessor, Warning, TEXT("Couldn't enumerate ROT table"));
			AccessResult = EAccessVisualStudioResult::VSInstanceUnknown;
		}
		RunningObjectTable->Release();
	}
	else
	{
		UE_LOG(LogVSAccessor, Warning, TEXT("Couldn't get ROT table"));
		AccessResult = EAccessVisualStudioResult::VSInstanceUnknown;
	}

	return AccessResult;
}