Beispiel #1
0
/* Newer COM libraries supply the functionality of
   bindObject() via CoGetObject(), but to avoid depending
   on that being around, we stick with our own implementation.
*/
HRESULT bindObject( const WCHAR* name, IID* iid, void** unk )
{
  HRESULT hr;
  IBindCtx    *bc;
  IMoniker    *mk;
  ULONG        count;

  if (!unk) return E_POINTER;
       else *unk = NULL;
  if (!iid) return E_POINTER;

  bc = NULL;
  mk = NULL;

  hr = CreateBindCtx(0, &bc);
  if (FAILED(hr)) return hr;

  hr = MkParseDisplayName(bc, name, &count, &mk);
  if (FAILED(hr)) { IUnknown_Release(bc); return hr; }

  hr = IMoniker_BindToObject( mk, bc, NULL, iid, unk );
  IUnknown_Release(mk);
  IUnknown_Release(bc);

  return hr;
}
Beispiel #2
0
/***********************************************************************
 *           MkParseDisplayNameEx (URLMON.@)
 */
HRESULT WINAPI MkParseDisplayNameEx(IBindCtx *pbc, LPCWSTR szDisplayName, ULONG *pchEaten, LPMONIKER *ppmk)
{
    TRACE("(%p %s %p %p)\n", pbc, debugstr_w(szDisplayName), pchEaten, ppmk);

    if(is_registered_protocol(szDisplayName)) {
        HRESULT hres;

        hres = CreateURLMoniker(NULL, szDisplayName, ppmk);
        if(SUCCEEDED(hres)) {
            *pchEaten = strlenW(szDisplayName);
            return hres;
        }
    }

    return MkParseDisplayName(pbc, szDisplayName, pchEaten, ppmk);
}
Beispiel #3
0
/***********************************************************************
 *             HlinkParseDisplayName (HLINK.@)
 */
HRESULT WINAPI HlinkParseDisplayName(LPBC pibc, LPCWSTR pwzDisplayName, BOOL fNoForceAbs,
        ULONG *pcchEaten, IMoniker **ppimk)
{
    static const WCHAR file_colonW[] = {'f','i','l','e',':'};
    ULONG eaten = 0;
    HRESULT hres;

    TRACE("(%p %s %x %p %p)\n", pibc, debugstr_w(pwzDisplayName), fNoForceAbs, pcchEaten, ppimk);

    if(fNoForceAbs)
        FIXME("Unsupported fNoForceAbs\n");

    if(!strncmpiW(pwzDisplayName, file_colonW, sizeof(file_colonW)/sizeof(WCHAR))) {
        pwzDisplayName += sizeof(file_colonW)/sizeof(WCHAR);
        eaten += sizeof(file_colonW)/sizeof(WCHAR);

        while(*pwzDisplayName == '/') {
            pwzDisplayName++;
            eaten++;
        }
    }else {
        hres = MkParseDisplayNameEx(pibc, pwzDisplayName, pcchEaten, ppimk);
        if(SUCCEEDED(hres))
            return hres;

        hres = MkParseDisplayName(pibc, pwzDisplayName, pcchEaten, ppimk);
        if(SUCCEEDED(hres))
            return hres;
    }

    hres = CreateFileMoniker(pwzDisplayName, ppimk);
    if(SUCCEEDED(hres))
        *pcchEaten = eaten + strlenW(pwzDisplayName);

    return hres;
}
Beispiel #4
0
/***********************************************************************
 *             HlinkParseDisplayName (HLINK.@)
 */
HRESULT WINAPI HlinkParseDisplayName(LPBC pibc, LPCWSTR pwzDisplayName, BOOL fNoForceAbs,
        ULONG *pcchEaten, IMoniker **ppimk)
{
    HRESULT hres;

    TRACE("(%p %s %x %p %p)\n", pibc, debugstr_w(pwzDisplayName), fNoForceAbs, pcchEaten, ppimk);

    if(fNoForceAbs)
        FIXME("Unsupported fNoForceAbs\n");

    hres = MkParseDisplayNameEx(pibc, pwzDisplayName, pcchEaten, ppimk);
    if(SUCCEEDED(hres))
        return hres;

    hres = MkParseDisplayName(pibc, pwzDisplayName, pcchEaten, ppimk);
    if(SUCCEEDED(hres))
        return hres;

    hres = CreateFileMoniker(pwzDisplayName, ppimk);
    if(SUCCEEDED(hres))
        *pcchEaten = strlenW(pwzDisplayName);

    return hres;
}
Beispiel #5
0
JNIEXPORT jlong JNICALL Java_com4j_Native_getObject(
	JNIEnv* env, jclass __unused__, jstring _fileName, jstring _progId) {

	HRESULT hr;

	if(_progId==NULL) {
		// case 1: just file name
		IBindCtxPtr pbc;
		ULONG cEaten;
		IMonikerPtr pmk;
		IDispatch* pDisp;

		hr = CreateBindCtx(NULL,&pbc);
		if(FAILED(hr)) {
			error(env,__FILE__,__LINE__,hr,"Failed to CreateBindCtx");
			return 0;
		}
		hr = MkParseDisplayName(pbc,JString(env,_fileName),&cEaten,&pmk);
		if(FAILED(hr)) {
			error(env,__FILE__,__LINE__,hr,"Failed to MkParseDisplayName");
			return 0;
		}
		hr = BindMoniker(pmk,0,__uuidof(IDispatch),(LPVOID*)&pDisp);
		if(FAILED(hr)) {
			error(env,__FILE__,__LINE__,hr,"Failed to bind moniker");
			return 0;
		}

		return reinterpret_cast<jlong>(pDisp);
	}

	JString progId(env,_progId);
	CLSID clsid;
	IUnknown* pUnk=NULL;

	hr = CLSIDFromProgID(progId,&clsid);
	if(FAILED(hr)) {
		error(env,__FILE__,__LINE__,hr,"Unrecognized progID");
		return 0;
	}

	if(_fileName==NULL) {
		// case 2: just progId
		hr = GetActiveObject(clsid,NULL,&pUnk);
		if(FAILED(hr)) {
			error(env,__FILE__,__LINE__,hr,"Failed to GetActiveObject");
			return 0;
		}
		return reinterpret_cast<jlong>(pUnk);
	}

	// case 3: both file name and progID
	hr = CoCreateInstance(clsid,NULL,CLSCTX_SERVER,__uuidof(IUnknown),(LPVOID*)&pUnk);
	if(FAILED(hr)) {
		error(env,__FILE__,__LINE__,hr,"Failed to create CoCreateInstance");
		return 0;
	}

	IPersistFilePtr ppf(pUnk);
	hr = ppf->Load(JString(env,_fileName),0);
	if(FAILED(hr)) {
		error(env,__FILE__,__LINE__,hr,"Failed to load from file");
		pUnk->Release();
		return 0;
	}

	return reinterpret_cast<jlong>(pUnk);
}
Beispiel #6
0
static HRESULT WINAPI IHlink_fnSetStringReference(IHlink* iface,
        DWORD grfHLSETF, LPCWSTR pwzTarget, LPCWSTR pwzLocation)
{
    HlinkImpl  *This = impl_from_IHlink(iface);

    TRACE("(%p)->(%i %s %s)\n", This, grfHLSETF, debugstr_w(pwzTarget),
            debugstr_w(pwzLocation));

    if(grfHLSETF > (HLINKSETF_TARGET | HLINKSETF_LOCATION) &&
            grfHLSETF < -(HLINKSETF_TARGET | HLINKSETF_LOCATION))
        return grfHLSETF;

    if (grfHLSETF & HLINKSETF_TARGET)
    {
        if (This->Moniker)
        {
            IMoniker_Release(This->Moniker);
            This->Moniker = NULL;
        }
        if (pwzTarget && *pwzTarget)
        {
            IMoniker *pMon;
            IBindCtx *pbc = NULL;
            ULONG eaten;
            HRESULT r;

            r = CreateBindCtx(0, &pbc);
            if (FAILED(r))
                return E_OUTOFMEMORY;

            r = MkParseDisplayName(pbc, pwzTarget, &eaten, &pMon);
            IBindCtx_Release(pbc);

            if (FAILED(r))
            {
                LPCWSTR p = strchrW(pwzTarget, ':');
                if (p && (p - pwzTarget > 1))
                    r = CreateURLMoniker(NULL, pwzTarget, &pMon);
                else
                    r = CreateFileMoniker(pwzTarget, &pMon);
                if (FAILED(r))
                {
                    ERR("couldn't create moniker for %s, failed with error 0x%08x\n",
                        debugstr_w(pwzTarget), r);
                    return r;
                }
            }

            IHlink_SetMonikerReference(iface, HLINKSETF_TARGET, pMon, NULL);
            IMoniker_Release(pMon);
        }
    }

    if (grfHLSETF & HLINKSETF_LOCATION)
    {
        heap_free(This->Location);
        This->Location = NULL;
        if (pwzLocation && *pwzLocation)
            This->Location = hlink_strdupW( pwzLocation );
    }

    return S_OK;
}
Beispiel #7
0
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_CAT_ERROR (dshowaudiosrc_debug, "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, unidevice, &dwEaten, &audiom);
      if (SUCCEEDED (hres)) {
        hres =
            IMoniker_BindToObject (audiom, lpbc, NULL, &IID_IBaseFilter,
            &src->audio_cap_filter);
        IMoniker_Release (audiom);
      }
      IBindCtx_Release (lpbc);
    }
  }

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

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

        hres =
            IPin_QueryInterface (capture_pin, &IID_IKsPropertySet,
            (void **) &pKs);
        if (SUCCEEDED (hres) && pKs) {
          DWORD cbReturned;
          GUID pin_category;
          RPC_STATUS rpcstatus;

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

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

            if (SUCCEEDED (IPin_QueryInterface (capture_pin,
                        &IID_IAMStreamConfig, (void **) &streamcaps))) {
              src->caps =
                  gst_dshowaudiosrc_getcaps_from_streamcaps (src, capture_pin,
                  streamcaps);
              IAMStreamConfig_Release (streamcaps);
            }
          }
          IKsPropertySet_Release (pKs);
        }
        IPin_Release (capture_pin);
      }
      IEnumPins_Release (enumpins);
    }
  }

  if (unidevice) {
    g_free (unidevice);
  }

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

  return NULL;
}
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;
}