Exemple #1
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();
}
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();
    }
}
Exemple #3
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;
}
/** 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;
}
Exemple #5
0
void CGPAXPlugin::UpdateURL()
{
	/*get absolute URL*/
	if (!strlen(m_url)) return;
	IMoniker* pMoniker	= NULL;
	LPOLESTR sDisplayName;

	if (SUCCEEDED(m_spClientSite->GetMoniker(OLEGETMONIKER_TEMPFORUSER,
									   OLEWHICHMK_CONTAINER,
									   &pMoniker) ) ) {
		char parent_url[1024];
		pMoniker->GetDisplayName(NULL, NULL, &sDisplayName);
		wcstombs(parent_url, sDisplayName, 300);
		pMoniker->Release();

		char *abs_url = gf_url_concatenate(parent_url, m_url);
		if (abs_url) {
			strcpy(m_url, abs_url);
			gf_free(abs_url);
		}
	}
}
void EnumDSF(void)
{
	ICreateDevEnum *pCreateDevEnum;
	IEnumMoniker *pEnumMoniker;
	IMoniker *pMoniker;
	ULONG nFetched;
	char buf[256];

	CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (PVOID *)&pCreateDevEnum);

	if (pCreateDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, &pEnumMoniker, 0) != S_OK)
	{
		pCreateDevEnum->Release();
		return;
	}

	pEnumMoniker->Reset();

	while (pEnumMoniker->Next(1, &pMoniker, &nFetched) == S_OK)
	{
		IPropertyBag *pPropertyBag;
		VARIANT varFriendlyName;
		WCHAR *pwszDisplayName;

		pMoniker->GetDisplayName(NULL, NULL, &pwszDisplayName);
		varFriendlyName.vt = VT_BSTR;
		pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropertyBag);
		pPropertyBag->Read(L"FriendlyName", &varFriendlyName, 0);
		wsprintf(buf, "DSF\t1\t%S\t%S\n", varFriendlyName.bstrVal, pwszDisplayName);
		printf("%s", buf);
		VariantClear(&varFriendlyName);
		CoTaskMemFree(pwszDisplayName);
		pPropertyBag->Release();
		pMoniker->Release();
	}

	pEnumMoniker->Release();
	pCreateDevEnum->Release();
}
Exemple #7
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;
}
Exemple #8
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;
}
Exemple #9
0
gchar *
gst_dshow_getdevice_from_devicename (const GUID * device_category,
    gchar ** device_name)
{
  gchar *ret = NULL;
  ICreateDevEnum *devices_enum = NULL;
  IEnumMoniker *enum_moniker = NULL;
  IMoniker *moniker = NULL;
  HRESULT hres = S_FALSE;
  ULONG fetched;
  gboolean bfound = FALSE;

  hres = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
      IID_ICreateDevEnum, (void **) &devices_enum);
  if (hres != S_OK) {
    /*error */
    goto clean;
  }

  hres = devices_enum->CreateClassEnumerator (*device_category,
      &enum_moniker, 0);
  if (hres != S_OK || !enum_moniker) {
    /*error */
    goto clean;
  }

  enum_moniker->Reset ();

  while (hres = enum_moniker->Next (1, &moniker, &fetched), hres == S_OK
      && !bfound) {
    IPropertyBag *property_bag = NULL;
    hres =
        moniker->BindToStorage (NULL, NULL, IID_IPropertyBag,
        (void **) &property_bag);
    if (SUCCEEDED (hres) && property_bag) {
      VARIANT varFriendlyName;
      VariantInit (&varFriendlyName);

      hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL);
      if (hres == S_OK && varFriendlyName.bstrVal) {
        gchar *friendly_name =
            g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal,
            wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL);

        if (!*device_name) {
          *device_name = g_strdup (friendly_name);
        }

        if (_stricmp (*device_name, friendly_name) == 0) {
          WCHAR *wszDisplayName = NULL;
          hres = moniker->GetDisplayName (NULL, NULL, &wszDisplayName);
          if (hres == S_OK && wszDisplayName) {
            ret = g_utf16_to_utf8 ((const gunichar2 *) wszDisplayName,
                wcslen (wszDisplayName), NULL, NULL, NULL);
            CoTaskMemFree (wszDisplayName);
          }
          bfound = TRUE;
        }
        SysFreeString (varFriendlyName.bstrVal);
      }
      property_bag->Release ();
    }
    moniker->Release ();
  }

clean:
  if (enum_moniker) {
    enum_moniker->Release ();
  }

  if (devices_enum) {
    devices_enum->Release ();
  }

  return ret;
}
HRESULT FindVideoCompressor(const std::wstring& format, IBaseFilter *&result)
{
	HRESULT hr = S_OK;

	CoInitialize(NULL);
	ComUninitial comUninitial;

	ICreateDevEnum *createDevEnum;
	hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&createDevEnum);
	if(FAILED(hr))
	{
		ErrorPrint("Create system device enum error", hr);
		return hr;
	}
	ComReleaser createDevEnumReleaser(createDevEnum);

	IEnumMoniker *enumMoniker;
	hr = createDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory, &enumMoniker, 0);
	if (FAILED(hr))
	{
		ErrorPrint("Create Video compressor enum error", hr);
		return hr;
	}

	IMoniker *moniker;
	while(S_OK == enumMoniker->Next(1, &moniker, NULL))
	{
		ComReleaser monikerReleaser(moniker);

		LPOLESTR oleDisplayName;
		hr = moniker->GetDisplayName(NULL, NULL, &oleDisplayName);
		if(FAILED(hr))
		{
			ErrorPrint("Get display name error", hr);
			continue;
		}
		std::wstring displayName(oleDisplayName);

		size_t slashPos;
		for (slashPos = 0; slashPos < displayName.size(); ++slashPos)
		{
			if(displayName[slashPos] == L'\\')
				break;
		}
		if(slashPos == displayName.size())
		{
			ErrorPrint("Find slash error");
			continue;
		}

		displayName = displayName.substr(slashPos+1);
		if (displayName == format)
		{
			hr = moniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&result);
			if(FAILED(hr))
			{
				ErrorPrint("Create video compressor filter error", hr);
				continue;
			}
			return S_OK;
		}

	}

	return E_FAIL;
}
/** 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;
}