/* From quartz, 2008/04/07 */ static HRESULT GetFilterInfo(IMoniker *pMoniker, GUID *pclsid, VARIANT *pvar) { static const WCHAR wszClsidName[] = {'C','L','S','I','D',0}; static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0}; IPropertyBag *pPropBagCat = NULL; HRESULT hr; VariantInit(pvar); V_VT(pvar) = VT_BSTR; hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID *) &pPropBagCat); if (SUCCEEDED(hr)) hr = IPropertyBag_Read(pPropBagCat, wszClsidName, pvar, NULL); if (SUCCEEDED(hr)) { hr = CLSIDFromString(V_UNION(pvar, bstrVal), pclsid); VariantClear(pvar); V_VT(pvar) = VT_BSTR; } if (SUCCEEDED(hr)) hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, pvar, NULL); if (SUCCEEDED(hr)) TRACE("Moniker = %s - %s\n", debugstr_guid(pclsid), debugstr_w(V_UNION(pvar, bstrVal))); if (pPropBagCat) IPropertyBag_Release(pPropBagCat); return hr; }
/*********************************************************************** * HlinkResolveMonikerForData (HLINK.@) */ HRESULT WINAPI HlinkResolveMonikerForData(LPMONIKER pimkReference, DWORD reserved, LPBC pibc, ULONG cFmtetc, FORMATETC *rgFmtetc, IBindStatusCallback *pibsc, LPMONIKER pimkBase) { LPOLESTR name = NULL; IBindCtx *bctx; DWORD mksys = 0; void *obj = NULL; HRESULT hres; TRACE("(%p %x %p %d %p %p %p)\n", pimkReference, reserved, pibc, cFmtetc, rgFmtetc, pibsc, pimkBase); if(cFmtetc || rgFmtetc || pimkBase) FIXME("Unsupported args\n"); hres = RegisterBindStatusCallback(pibc, pibsc, NULL /* FIXME */, 0); if(FAILED(hres)) return hres; hres = IMoniker_IsSystemMoniker(pimkReference, &mksys); if(SUCCEEDED(hres) && mksys != MKSYS_URLMONIKER) WARN("sysmk = %x\n", mksys); /* FIXME: What is it for? */ CreateBindCtx(0, &bctx); hres = IMoniker_GetDisplayName(pimkReference, bctx, NULL, &name); IBindCtx_Release(bctx); if(SUCCEEDED(hres)) { TRACE("got display name %s\n", debugstr_w(name)); CoTaskMemFree(name); } return IMoniker_BindToStorage(pimkReference, pibc, NULL, &IID_IUnknown, &obj); }
HRESULT download_to_cache(IUri *uri, stop_cache_binding_proc_t proc, void *ctx, IBindStatusCallback *callback) { DownloadBSC *dwl_bsc; IBindCtx *bindctx; IMoniker *mon; IUnknown *unk; HRESULT hres; hres = DownloadBSC_Create(callback, NULL, &dwl_bsc); if(FAILED(hres)) return hres; dwl_bsc->onstop_proc = proc; dwl_bsc->ctx = ctx; dwl_bsc->bindf = BINDF_ASYNCHRONOUS; hres = CreateAsyncBindCtx(0, &dwl_bsc->IBindStatusCallback_iface, NULL, &bindctx); IBindStatusCallback_Release(&dwl_bsc->IBindStatusCallback_iface); if(FAILED(hres)) return hres; hres = CreateURLMonikerEx2(NULL, uri, &mon, 0); if(FAILED(hres)) { IBindCtx_Release(bindctx); return hres; } hres = IMoniker_BindToStorage(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk); IMoniker_Release(mon); IBindCtx_Release(bindctx); if(SUCCEEDED(hres) && unk) IUnknown_Release(unk); return hres; }
static DWORD WINAPI download_proc(PVOID arg) { IMoniker *mon; IBindCtx *bctx; IStream *str = NULL; HRESULT hres; CreateURLMoniker(NULL, url, &mon); heap_free(url); url = NULL; CreateAsyncBindCtx(0, &InstallCallback, 0, &bctx); hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&str); IBindCtx_Release(bctx); if(FAILED(hres)) { ERR("BindToStorage failed: %08x\n", hres); return 0; } if(str) IStream_Release(str); return 0; }
static HRESULT WINAPI xmldoc_put_URL(IXMLDocument *iface, BSTR p) { WCHAR url[INTERNET_MAX_URL_LENGTH]; IStream *stream; IBindCtx *bctx; IMoniker *moniker; IPersistStreamInit *persist; HRESULT hr; TRACE("(%p, %s)\n", iface, debugstr_w(p)); if (!p) return E_INVALIDARG; if (!PathIsURLW(p)) { WCHAR fullpath[MAX_PATH]; DWORD needed = sizeof(url) / sizeof(WCHAR); if (!PathSearchAndQualifyW(p, fullpath, sizeof(fullpath) / sizeof(WCHAR))) { ERR("can't find path\n"); return E_FAIL; } if (FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0))) { ERR("can't create url from path\n"); return E_FAIL; } p = url; } hr = CreateURLMoniker(NULL, p, &moniker); if (FAILED(hr)) return hr; CreateAsyncBindCtx(0, &xmldoc_bsc.IBindStatusCallback_iface, 0, &bctx); hr = IMoniker_BindToStorage(moniker, bctx, NULL, &IID_IStream, (LPVOID *)&stream); IBindCtx_Release(bctx); IMoniker_Release(moniker); if (FAILED(hr)) return hr; hr = IXMLDocument_QueryInterface(iface, &IID_IPersistStreamInit, (LPVOID *)&persist); if (FAILED(hr)) { IStream_Release(stream); return hr; } hr = IPersistStreamInit_Load(persist, stream); IPersistStreamInit_Release(persist); IStream_Release(stream); return hr; }
/* Helper function, checks if filter with given name was enumerated. */ static BOOL enum_find_filter(const WCHAR *wszFilterName, IEnumMoniker *pEnum) { IMoniker *pMoniker = NULL; BOOL found = FALSE; ULONG nb; HRESULT hr; static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0}; while(!found && IEnumMoniker_Next(pEnum, 1, &pMoniker, &nb) == S_OK) { IPropertyBag * pPropBagCat = NULL; VARIANT var; VariantInit(&var); hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat); ok(SUCCEEDED(hr), "IMoniker_BindToStorage failed with %x\n", hr); if (FAILED(hr) || !pPropBagCat) { VariantClear(&var); IMoniker_Release(pMoniker); continue; } hr = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL); ok(SUCCEEDED(hr), "IPropertyBag_Read failed with %x\n", hr); if (SUCCEEDED(hr)) { CHAR val1[512], val2[512]; WideCharToMultiByte(CP_ACP, 0, V_BSTR(&var), -1, val1, sizeof(val1), 0, 0); WideCharToMultiByte(CP_ACP, 0, wszFilterName, -1, val2, sizeof(val2), 0, 0); if (!lstrcmpA(val1, val2)) found = TRUE; } IPropertyBag_Release(pPropBagCat); IMoniker_Release(pMoniker); VariantClear(&var); } return found; }
HRESULT bind_url(IMoniker *mon, HRESULT (*onDataAvailable)(void*,char*,DWORD), void *obj, bsc_t **ret) { bsc_t *bsc; IBindCtx *pbc; HRESULT hr; TRACE("%p\n", mon); hr = CreateBindCtx(0, &pbc); if(FAILED(hr)) return hr; bsc = heap_alloc(sizeof(bsc_t)); bsc->IBindStatusCallback_iface.lpVtbl = &bsc_vtbl; bsc->ref = 1; bsc->obj = obj; bsc->onDataAvailable = onDataAvailable; bsc->binding = NULL; bsc->memstream = NULL; bsc->hres = S_OK; hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0); if(SUCCEEDED(hr)) { IStream *stream; hr = IMoniker_BindToStorage(mon, pbc, NULL, &IID_IStream, (LPVOID*)&stream); if(stream) IStream_Release(stream); IBindCtx_Release(pbc); } if(FAILED(hr)) { IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface); bsc = NULL; } *ret = bsc; return hr; }
/*********************************************************************** * URLDownloadToFileW (URLMON.@) * * Downloads URL szURL to file szFileName and call lpfnCB callback to * report progress. * * PARAMS * pCaller [I] controlling IUnknown interface. * szURL [I] URL of the file to download * szFileName [I] file name to store the content of the URL * dwReserved [I] reserved - set to 0 * lpfnCB [I] callback for progress report * * RETURNS * S_OK on success */ HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller, LPCWSTR szURL, LPCWSTR szFileName, DWORD dwReserved, LPBINDSTATUSCALLBACK lpfnCB) { IBindStatusCallback *callback; IUnknown *unk; IMoniker *mon; IBindCtx *bindctx; HRESULT hres; TRACE("(%p %s %s %d %p)\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB); if(pCaller) FIXME("pCaller not supported\n"); hres = DownloadBSC_Create(lpfnCB, szFileName, &callback); if(FAILED(hres)) return hres; hres = CreateAsyncBindCtx(0, callback, NULL, &bindctx); IBindStatusCallback_Release(callback); if(FAILED(hres)) return hres; hres = CreateURLMoniker(NULL, szURL, &mon); if(FAILED(hres)) { IBindCtx_Release(bindctx); return hres; } hres = IMoniker_BindToStorage(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk); IMoniker_Release(mon); IBindCtx_Release(bindctx); if(unk) IUnknown_Release(unk); return hres == MK_S_ASYNCHRONOUS ? S_OK : hres; }
static HRESULT URLStartDownload(LPCWSTR szURL, LPSTREAM *ppStream, IBindStatusCallback *pBSC) { HRESULT hr; IMoniker *pMoniker; IBindCtx *pbc; *ppStream = NULL; hr = CreateURLMoniker(NULL, szURL, &pMoniker); if (FAILED(hr)) return hr; hr = CreateBindCtx(0, &pbc); if (FAILED(hr)) { IMoniker_Release(pMoniker); return hr; } hr = RegisterBindStatusCallback(pbc, pBSC, NULL, 0); if (FAILED(hr)) { IBindCtx_Release(pbc); IMoniker_Release(pMoniker); return hr; } hr = IMoniker_BindToStorage(pMoniker, pbc, NULL, &IID_IStream, (void **)ppStream); /* BindToStorage returning E_PENDING because it's asynchronous is not an error */ if (hr == E_PENDING) hr = S_OK; IBindCtx_Release(pbc); IMoniker_Release(pMoniker); return hr; }
static BOOL start_download(void) { IBindCtx *bind_ctx; IMoniker *mon; IUnknown *tmp; HRESULT hres; hres = CreateURLMoniker(NULL, url, &mon); if(FAILED(hres)) return FALSE; hres = CreateAsyncBindCtx(0, &InstallCallback, NULL, &bind_ctx); if(SUCCEEDED(hres)) { hres = IMoniker_BindToStorage(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&tmp); IBindCtx_Release(bind_ctx); } IMoniker_Release(mon); if(FAILED(hres)) return FALSE; if(tmp) IUnknown_Release(tmp); return TRUE; }
/********************************************************************** * DEVENUM_CreateSpecialCategories (INTERNAL) * * Creates the keys in the registry for the dynamic categories */ static HRESULT DEVENUM_CreateSpecialCategories(void) { HRESULT res; WCHAR szDSoundNameFormat[MAX_PATH + 1]; WCHAR szDSoundName[MAX_PATH + 1]; DWORD iDefaultDevice = -1; UINT numDevs; IFilterMapper2 * pMapper = NULL; REGFILTER2 rf2; REGFILTERPINS2 rfp2; WCHAR path[MAX_PATH]; HKEY basekey; if (DEVENUM_populate_handle) return S_OK; DEVENUM_populate_handle = CreateEventW(NULL, TRUE, FALSE, DEVENUM_populate_handle_nameW); if (GetLastError() == ERROR_ALREADY_EXISTS) { /* Webcams can take some time to scan if the driver is badly written and it enables them, * so have a 10 s timeout here */ if (WaitForSingleObject(DEVENUM_populate_handle, 10000) == WAIT_TIMEOUT) WARN("Waiting for object timed out\n"); TRACE("No need to rescan\n"); return S_OK; } TRACE("Scanning for devices\n"); /* Since devices can change between session, for example because you just plugged in a webcam * or switched from pulseaudio to alsa, delete all old devices first */ if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioRendererCategory, &basekey, path, MAX_PATH))) RegDeleteTreeW(basekey, path); if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_AudioInputDeviceCategory, &basekey, path, MAX_PATH))) RegDeleteTreeW(basekey, path); if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_VideoInputDeviceCategory, &basekey, path, MAX_PATH))) RegDeleteTreeW(basekey, path); if (SUCCEEDED(DEVENUM_GetCategoryKey(&CLSID_MidiRendererCategory, &basekey, path, MAX_PATH))) RegDeleteTreeW(basekey, path); rf2.dwVersion = 2; rf2.dwMerit = MERIT_PREFERRED; rf2.u.s1.cPins2 = 1; rf2.u.s1.rgPins2 = &rfp2; rfp2.cInstances = 1; rfp2.nMediums = 0; rfp2.lpMedium = NULL; rfp2.clsPinCategory = &IID_NULL; if (!LoadStringW(DEVENUM_hInstance, IDS_DEVENUM_DS, szDSoundNameFormat, sizeof(szDSoundNameFormat)/sizeof(szDSoundNameFormat[0])-1)) { ERR("Couldn't get string resource (GetLastError() is %d)\n", GetLastError()); return HRESULT_FROM_WIN32(GetLastError()); } res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2, (void **) &pMapper); /* * Fill in info for devices */ if (SUCCEEDED(res)) { UINT i; WAVEOUTCAPSW wocaps; WAVEINCAPSW wicaps; MIDIOUTCAPSW mocaps; REGPINTYPES * pTypes; numDevs = waveOutGetNumDevs(); res = DEVENUM_CreateAMCategoryKey(&CLSID_AudioRendererCategory); if (FAILED(res)) /* can't register any devices in this category */ numDevs = 0; rfp2.dwFlags = REG_PINFLAG_B_RENDERER; for (i = 0; i < numDevs; i++) { if (waveOutGetDevCapsW(i, &wocaps, sizeof(WAVEOUTCAPSW)) == MMSYSERR_NOERROR) { IMoniker * pMoniker = NULL; rfp2.nMediaTypes = 1; pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES)); if (!pTypes) { IFilterMapper2_Release(pMapper); return E_OUTOFMEMORY; } /* FIXME: Native devenum seems to register a lot more types for * DSound than we do. Not sure what purpose they serve */ pTypes[0].clsMajorType = &MEDIATYPE_Audio; pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM; rfp2.lpMediaType = pTypes; res = IFilterMapper2_RegisterFilter(pMapper, &CLSID_AudioRender, wocaps.szPname, &pMoniker, &CLSID_AudioRendererCategory, wocaps.szPname, &rf2); /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */ if (pMoniker) { IMoniker_Release(pMoniker); pMoniker = NULL; } wsprintfW(szDSoundName, szDSoundNameFormat, wocaps.szPname); res = IFilterMapper2_RegisterFilter(pMapper, &CLSID_DSoundRender, szDSoundName, &pMoniker, &CLSID_AudioRendererCategory, szDSoundName, &rf2); /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */ if (pMoniker) IMoniker_Release(pMoniker); if (i == iDefaultDevice) { FIXME("Default device\n"); } CoTaskMemFree(pTypes); } } numDevs = waveInGetNumDevs(); res = DEVENUM_CreateAMCategoryKey(&CLSID_AudioInputDeviceCategory); if (FAILED(res)) /* can't register any devices in this category */ numDevs = 0; rfp2.dwFlags = REG_PINFLAG_B_OUTPUT; for (i = 0; i < numDevs; i++) { if (waveInGetDevCapsW(i, &wicaps, sizeof(WAVEINCAPSW)) == MMSYSERR_NOERROR) { IMoniker * pMoniker = NULL; rfp2.nMediaTypes = 1; pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES)); if (!pTypes) { IFilterMapper2_Release(pMapper); return E_OUTOFMEMORY; } /* FIXME: Not sure if these are correct */ pTypes[0].clsMajorType = &MEDIATYPE_Audio; pTypes[0].clsMinorType = &MEDIASUBTYPE_PCM; rfp2.lpMediaType = pTypes; res = IFilterMapper2_RegisterFilter(pMapper, &CLSID_AudioRecord, wicaps.szPname, &pMoniker, &CLSID_AudioInputDeviceCategory, wicaps.szPname, &rf2); /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */ if (pMoniker) IMoniker_Release(pMoniker); CoTaskMemFree(pTypes); } } numDevs = midiOutGetNumDevs(); res = DEVENUM_CreateAMCategoryKey(&CLSID_MidiRendererCategory); if (FAILED(res)) /* can't register any devices in this category */ numDevs = 0; rfp2.dwFlags = REG_PINFLAG_B_RENDERER; for (i = 0; i < numDevs; i++) { if (midiOutGetDevCapsW(i, &mocaps, sizeof(MIDIOUTCAPSW)) == MMSYSERR_NOERROR) { IMoniker * pMoniker = NULL; rfp2.nMediaTypes = 1; pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES)); if (!pTypes) { IFilterMapper2_Release(pMapper); return E_OUTOFMEMORY; } /* FIXME: Not sure if these are correct */ pTypes[0].clsMajorType = &MEDIATYPE_Midi; pTypes[0].clsMinorType = &MEDIASUBTYPE_None; rfp2.lpMediaType = pTypes; res = IFilterMapper2_RegisterFilter(pMapper, &CLSID_AVIMIDIRender, mocaps.szPname, &pMoniker, &CLSID_MidiRendererCategory, mocaps.szPname, &rf2); /* FIXME: do additional stuff with IMoniker here, depending on what RegisterFilter does */ /* Native version sets MidiOutId */ if (pMoniker) IMoniker_Release(pMoniker); if (i == iDefaultDevice) { FIXME("Default device\n"); } CoTaskMemFree(pTypes); } } res = DEVENUM_CreateAMCategoryKey(&CLSID_VideoInputDeviceCategory); if (SUCCEEDED(res)) for (i = 0; i < 10; i++) { WCHAR szDeviceName[32], szDeviceVersion[32], szDevicePath[10]; if (capGetDriverDescriptionW ((WORD) i, szDeviceName, sizeof(szDeviceName)/sizeof(WCHAR), szDeviceVersion, sizeof(szDeviceVersion)/sizeof(WCHAR))) { IMoniker * pMoniker = NULL; IPropertyBag * pPropBag = NULL; WCHAR dprintf[] = { 'v','i','d','e','o','%','d',0 }; snprintfW(szDevicePath, sizeof(szDevicePath)/sizeof(WCHAR), dprintf, i); /* The above code prevents 1 device with a different ID overwriting another */ rfp2.nMediaTypes = 1; pTypes = CoTaskMemAlloc(rfp2.nMediaTypes * sizeof(REGPINTYPES)); if (!pTypes) { IFilterMapper2_Release(pMapper); return E_OUTOFMEMORY; } pTypes[0].clsMajorType = &MEDIATYPE_Video; pTypes[0].clsMinorType = &MEDIASUBTYPE_None; rfp2.lpMediaType = pTypes; res = IFilterMapper2_RegisterFilter(pMapper, &CLSID_VfwCapture, szDeviceName, &pMoniker, &CLSID_VideoInputDeviceCategory, szDevicePath, &rf2); if (pMoniker) { OLECHAR wszVfwIndex[] = { 'V','F','W','I','n','d','e','x',0 }; VARIANT var; V_VT(&var) = VT_I4; V_UNION(&var, ulVal) = i; res = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag); if (SUCCEEDED(res)) res = IPropertyBag_Write(pPropBag, wszVfwIndex, &var); IMoniker_Release(pMoniker); } if (i == iDefaultDevice) FIXME("Default device\n"); CoTaskMemFree(pTypes); } } } if (pMapper) IFilterMapper2_Release(pMapper); SetEvent(DEVENUM_populate_handle); return res; }
/** * Cycle through available devices using the device enumerator devenum, * retrieve the device with type specified by devtype and return the * pointer to the object found in *pfilter. * If pfilter is NULL, list all device names. */ static int dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter **pfilter) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; IEnumMoniker *classenum = NULL; IMoniker *m = NULL; const char *device_name = ctx->device_name[devtype]; int skip = (devtype == VideoDevice) ? ctx->video_device_number : ctx->audio_device_number; int r; const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory, &CLSID_AudioInputDeviceCategory }; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio only"; const char *sourcetypename = (sourcetype == VideoSourceDevice) ? "video" : "audio"; r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype], (IEnumMoniker **) &classenum, 0); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices (or none found).\n", devtypename); return AVERROR(EIO); } while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) { IPropertyBag *bag = NULL; char *friendly_name = NULL; char *unique_name = NULL; VARIANT var; IBindCtx *bind_ctx = NULL; LPOLESTR olestr = NULL; LPMALLOC co_malloc = NULL; int i; r = CoGetMalloc(1, &co_malloc); if (r != S_OK) goto fail1; r = CreateBindCtx(0, &bind_ctx); if (r != S_OK) goto fail1; /* GetDisplayname works for both video and audio, DevicePath doesn't */ r = IMoniker_GetDisplayName(m, bind_ctx, NULL, &olestr); if (r != S_OK) goto fail1; unique_name = dup_wchar_to_utf8(olestr); /* replace ':' with '_' since we use : to delineate between sources */ for (i = 0; i < strlen(unique_name); i++) { if (unique_name[i] == ':') unique_name[i] = '_'; } r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag); if (r != S_OK) goto fail1; var.vt = VT_BSTR; r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL); if (r != S_OK) goto fail1; friendly_name = dup_wchar_to_utf8(var.bstrVal); if (pfilter) { if (strcmp(device_name, friendly_name) && strcmp(device_name, unique_name)) goto fail1; if (!skip--) { r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Unable to BindToObject for %s\n", device_name); goto fail1; } } } else { av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name); av_log(avctx, AV_LOG_INFO, " Alternative name \"%s\"\n", unique_name); } fail1: if (olestr && co_malloc) IMalloc_Free(co_malloc, olestr); if (bind_ctx) IBindCtx_Release(bind_ctx); av_free(friendly_name); av_free(unique_name); if (bag) IPropertyBag_Release(bag); IMoniker_Release(m); } IEnumMoniker_Release(classenum); if (pfilter) { if (!device_filter) { av_log(avctx, AV_LOG_ERROR, "Could not find %s device with name [%s] among source devices of type %s.\n", devtypename, device_name, sourcetypename); return AVERROR(EIO); } *pfilter = device_filter; } return 0; }
/** * Cycle through available devices using the device enumerator devenum, * retrieve the device with type specified by devtype and return the * pointer to the object found in *pfilter. * If pfilter is NULL, list all device names. */ static int dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, enum dshowDeviceType devtype, IBaseFilter **pfilter) { struct dshow_ctx *ctx = avctx->priv_data; IBaseFilter *device_filter = NULL; IEnumMoniker *classenum = NULL; IMoniker *m = NULL; const char *device_name = ctx->device_name[devtype]; int skip = (devtype == VideoDevice) ? ctx->video_device_number : ctx->audio_device_number; int r; const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory, &CLSID_AudioInputDeviceCategory }; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype], (IEnumMoniker **) &classenum, 0); if (r != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n", devtypename); return AVERROR(EIO); } while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) { IPropertyBag *bag = NULL; char *buf = NULL; VARIANT var; r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag); if (r != S_OK) goto fail1; var.vt = VT_BSTR; r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL); if (r != S_OK) goto fail1; buf = dup_wchar_to_utf8(var.bstrVal); if (pfilter) { if (strcmp(device_name, buf)) goto fail1; if (!skip--) IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter); } else { av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf); } fail1: if (buf) av_free(buf); if (bag) IPropertyBag_Release(bag); IMoniker_Release(m); } IEnumMoniker_Release(classenum); if (pfilter) { if (!device_filter) { av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n", devtypename); return AVERROR(EIO); } *pfilter = device_filter; } return 0; }
HRESULT bind_url(LPCWSTR url, HRESULT (*onDataAvailable)(void*,char*,DWORD), void *obj, bsc_t **ret) { WCHAR fileUrl[INTERNET_MAX_URL_LENGTH]; bsc_t *bsc; IBindCtx *pbc; HRESULT hr; TRACE("%s\n", debugstr_w(url)); if(!PathIsURLW(url)) { WCHAR fullpath[MAX_PATH]; DWORD needed = sizeof(fileUrl)/sizeof(WCHAR); if(!PathSearchAndQualifyW(url, fullpath, sizeof(fullpath)/sizeof(WCHAR))) { WARN("can't find path\n"); return E_FAIL; } if(FAILED(UrlCreateFromPathW(url, fileUrl, &needed, 0))) { ERR("can't create url from path\n"); return E_FAIL; } url = fileUrl; } hr = CreateBindCtx(0, &pbc); if(FAILED(hr)) return hr; bsc = HeapAlloc(GetProcessHeap(), 0, sizeof(bsc_t)); bsc->lpVtbl = &bsc_vtbl; bsc->ref = 1; bsc->obj = obj; bsc->onDataAvailable = onDataAvailable; bsc->binding = NULL; bsc->memstream = NULL; hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&bsc->lpVtbl, NULL, 0); if(SUCCEEDED(hr)) { IMoniker *moniker; hr = CreateURLMoniker(NULL, url, &moniker); if(SUCCEEDED(hr)) { IStream *stream; hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream); IMoniker_Release(moniker); if(stream) IStream_Release(stream); } IBindCtx_Release(pbc); } if(FAILED(hr)) { IBindStatusCallback_Release((IBindStatusCallback*)&bsc->lpVtbl); bsc = NULL; } *ret = bsc; return hr; }
static HRESULT BindStatusCallback_create(httprequest* This, BindStatusCallback **obj, const VARIANT *body) { BindStatusCallback *bsc; IBindCtx *pbc; HRESULT hr; hr = CreateBindCtx(0, &pbc); if (hr != S_OK) return hr; bsc = heap_alloc(sizeof(*bsc)); if (!bsc) { IBindCtx_Release(pbc); return E_OUTOFMEMORY; } bsc->IBindStatusCallback_iface.lpVtbl = &BindStatusCallbackVtbl; bsc->IHttpNegotiate_iface.lpVtbl = &BSCHttpNegotiateVtbl; bsc->ref = 1; bsc->request = This; bsc->binding = NULL; bsc->stream = NULL; bsc->body = NULL; TRACE("created callback %p\n", bsc); if (This->verb != BINDVERB_GET) { if (V_VT(body) == VT_BSTR) { LONG size = SysStringLen(V_BSTR(body)) * sizeof(WCHAR); void *ptr; bsc->body = GlobalAlloc(GMEM_FIXED, size); if (!bsc->body) { heap_free(bsc); return E_OUTOFMEMORY; } ptr = GlobalLock(bsc->body); memcpy(ptr, V_BSTR(body), size); GlobalUnlock(bsc->body); } else FIXME("unsupported body data type %d\n", V_VT(body)); } hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0); if (hr == S_OK) { IMoniker *moniker; hr = CreateURLMoniker(NULL, This->url, &moniker); if (hr == S_OK) { IStream *stream; hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (void**)&stream); IMoniker_Release(moniker); if (stream) IStream_Release(stream); } IBindCtx_Release(pbc); } if (FAILED(hr)) { IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface); bsc = NULL; } *obj = bsc; return hr; }
static HRESULT WINAPI XMLView_PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable, IMoniker *pimkName, LPBC pibc, DWORD grfMode) { static const WCHAR XSLParametersW[] = {'X','S','L','P','a','r','a','m','e','t','e','r','s',0}; static const WCHAR XMLBufferStreamW[] = {'X','M','L','B','u','f','f','e','r','S','t','r','e','a','m',0}; static const WCHAR DWNBINDINFOW[] = {'_','_','D','W','N','B','I','N','D','I','N','F','O',0}; static const WCHAR HTMLLOADOPTIONSW[] = {'_','_','H','T','M','L','L','O','A','D','O','P','T','I','O','N','S',0}; static const WCHAR BSCBHolderW[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 }; XMLView *This = impl_from_IPersistMoniker(iface); IPersistMoniker *html_persist_mon; IBindStatusCallback *bsc, *bsc_html; IBindCtx *bindctx; IStream *stream; IMoniker *mon; IUnknown *unk; HRESULT hres; TRACE("(%p)->(%x %p %p %x)\n", This, fFullyAvailable, pimkName, pibc, grfMode); hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)XSLParametersW, &unk); if(SUCCEEDED(hres)) { FIXME("ignoring XSLParameters\n"); IUnknown_Release(unk); } hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)XMLBufferStreamW, &unk); if(SUCCEEDED(hres)) { FIXME("ignoring XMLBufferStream\n"); IUnknown_Release(unk); } hres = CreateBindCtx(0, &bindctx); if(FAILED(hres)) return hres; hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)DWNBINDINFOW, &unk); if(SUCCEEDED(hres)) { IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)DWNBINDINFOW, unk); IUnknown_Release(unk); } hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)HTMLLOADOPTIONSW, &unk); if(SUCCEEDED(hres)) { IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)HTMLLOADOPTIONSW, unk); IUnknown_Release(unk); } hres = IBindCtx_GetObjectParam(pibc, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, &unk); if(SUCCEEDED(hres)) { IBindCtx_RegisterObjectParam(bindctx, (LPOLESTR)SZ_HTML_CLIENTSITE_OBJECTPARAM, unk); IUnknown_Release(unk); } hres = CreateStreamOnHGlobal(NULL, TRUE, &stream); if(FAILED(hres)) { IBindCtx_Release(bindctx); return hres; } if(This->mon) IMoniker_Release(This->mon); This->mon = pimkName; IMoniker_AddRef(This->mon); hres = XMLView_Moniker_Create(This->mon, stream, &mon); if(FAILED(hres)) { IStream_Release(stream); IBindCtx_Release(bindctx); return hres; } hres = IUnknown_QueryInterface(This->html_doc, &IID_IPersistMoniker, (void**)&html_persist_mon); if(FAILED(hres)) { IMoniker_Release(mon); IStream_Release(stream); IBindCtx_Release(bindctx); return hres; } hres = IPersistMoniker_Load(html_persist_mon, FALSE, mon, bindctx, 0); IPersistMoniker_Release(html_persist_mon); IMoniker_Release(mon); if(FAILED(hres)) { IStream_Release(stream); IBindCtx_Release(bindctx); return hres; } hres = IBindCtx_GetObjectParam(bindctx, (LPOLESTR)BSCBHolderW, &unk); IBindCtx_Release(bindctx); if(FAILED(hres)) { IStream_Release(stream); return hres; } hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&bsc_html); IUnknown_Release(unk); if(FAILED(hres)) { IStream_Release(stream); return hres; } hres = XMLView_BindStatusCallback_Create(bsc_html, This->mon, stream, &bsc); IStream_Release(stream); if(FAILED(hres)) { IBindStatusCallback_OnStopBinding(bsc_html, hres, NULL); IBindStatusCallback_Release(bsc_html); return hres; } hres = RegisterBindStatusCallback(pibc, bsc, NULL, 0); IBindStatusCallback_Release(bsc); if(FAILED(hres)) { IBindStatusCallback_OnStopBinding(bsc_html, hres, NULL); IBindStatusCallback_Release(bsc_html); return hres; } hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&stream); if(FAILED(hres)) { IBindStatusCallback_OnStopBinding(bsc_html, hres, NULL); IBindStatusCallback_Release(bsc_html); return hres; } if(stream) IStream_Release(stream); IBindStatusCallback_Release(bsc_html); return S_OK; }
static void test_devenum(IBindCtx *bind_ctx) { HRESULT res; ICreateDevEnum* create_devenum; IEnumMoniker* enum_moniker = NULL; int i; res = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&create_devenum); if (res != S_OK) { skip("Cannot create SystemDeviceEnum object (%x)\n", res); return; } for (i = 0; i < (sizeof(am_categories) / sizeof(struct category)); i++) { if (winetest_debug > 1) trace("%s:\n", am_categories[i].name); res = ICreateDevEnum_CreateClassEnumerator(create_devenum, am_categories[i].clsid, &enum_moniker, 0); ok(SUCCEEDED(res), "Cannot create enum moniker (res = %x)\n", res); if (res == S_OK) { IMoniker* moniker; while (IEnumMoniker_Next(enum_moniker, 1, &moniker, NULL) == S_OK) { IPropertyBag* prop_bag = NULL; VARIANT var; HRESULT hr; VariantInit(&var); hr = IMoniker_BindToStorage(moniker, bind_ctx, NULL, &IID_IPropertyBag, (LPVOID*)&prop_bag); ok(hr == S_OK, "IMoniker_BindToStorage failed with error %x\n", hr); if (SUCCEEDED(hr)) { hr = IPropertyBag_Read(prop_bag, friendly_name, &var, NULL); ok((hr == S_OK) || broken(hr == 0x80070002), "IPropertyBag_Read failed with error %x\n", hr); if (SUCCEEDED(hr)) { if (winetest_debug > 1) trace(" %s\n", wine_dbgstr_w(V_UNION(&var, bstrVal))); VariantClear(&var); } else { trace(" ???\n"); } } if (prop_bag) IPropertyBag_Release(prop_bag); IMoniker_Release(moniker); } IEnumMoniker_Release(enum_moniker); } } ICreateDevEnum_Release(create_devenum); }
static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) { HRESULT hr = S_OK; static const WCHAR szName[] = {'s','z','N','a','m','e',0}; static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0}; static const WCHAR szClsidCat[] = {'s','z','C','l','s','i','d','C','a','t',0}; static const WCHAR szClsidFilter[] = {'s','z','C','l','s','i','d','F','i','l','t','e','r',0}; static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0}; static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0}; static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0}; /* static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0}; static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0}; */ VARIANT v; static const WCHAR wszClsidName[] = {'C','L','S','I','D',0}; static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0}; static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0}; /*static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};*/ ICreateDevEnum* pCreateDevEnum = NULL; IEnumMoniker* pEmCat = NULL; IMoniker* pMCat = NULL; /** */ hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, &IID_ICreateDevEnum, (void**) &pCreateDevEnum); if (FAILED(hr)) return hr; hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0); if (FAILED(hr)) goto out_show_filters; VariantInit(&v); while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) { IPropertyBag* pPropBag = NULL; CLSID clsidCat; hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag); if (SUCCEEDED(hr)) { WCHAR* wszCatName = NULL; WCHAR* wszCatClsid = NULL; hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0); wszCatName = SysAllocString(V_BSTR(&v)); VariantClear(&v); hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0); wszCatClsid = SysAllocString(V_BSTR(&v)); hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat); VariantClear(&v); /* hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0); hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v); VariantClear(&v); */ if (SUCCEEDED(hr)) { IEnumMoniker* pEnum = NULL; IMoniker* pMoniker = NULL; hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0); FIXME("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum); if (FAILED(hr) || pEnum == NULL) { goto class_enum_failed; } while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) { IPropertyBag* pPropFilterBag = NULL; FIXME("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker); hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag); if (SUCCEEDED(hr)) { LPBYTE pData = NULL; LPBYTE pCurrent = NULL; struct REG_RF* prrf = NULL; VARIANT v_data; DWORD it; DWORD dwNOutputs = 0; DWORD dwNInputs = 0; V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(wszCatName); hr = IDxDiagContainerImpl_AddProp(pSubCont, szCatName, &v); VariantClear(&v); V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(wszCatClsid); hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidCat, &v); VariantClear(&v); hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0); hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v); FIXME("\tName:%s\n", debugstr_w(V_BSTR(&v))); VariantClear(&v); hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0); FIXME("\tClsid:%s\n", debugstr_w(V_BSTR(&v))); hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidFilter, &v); VariantClear(&v); hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL); hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData); prrf = (struct REG_RF*) pData; pCurrent = pData; VariantInit(&v_data); V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = prrf->dwVersion; hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v_data); VariantClear(&v_data); V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = prrf->dwMerit; hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v_data); VariantClear(&v_data); pCurrent += sizeof(struct REG_RF); for (it = 0; it < prrf->dwPins; ++it) { struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent; UINT j; if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs; else ++dwNInputs; pCurrent += sizeof(struct REG_RFP); if (prrfp->bCategory) { pCurrent += sizeof(DWORD); } for (j = 0; j < prrfp->dwMediaTypes; ++j) { struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent; pCurrent += sizeof(*prt); } for (j = 0; j < prrfp->dwMediums; ++j) { DWORD dwOffset = *(DWORD*) pCurrent; pCurrent += sizeof(dwOffset); } } V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = dwNInputs; hr = IDxDiagContainerImpl_AddProp(pSubCont, dwInputs, &v_data); VariantClear(&v_data); V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = dwNOutputs; hr = IDxDiagContainerImpl_AddProp(pSubCont, dwOutputs, &v_data); VariantClear(&v_data); SafeArrayUnaccessData(V_UNION(&v, parray)); VariantClear(&v); } IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL; } IEnumMoniker_Release(pEnum); pEnum = NULL; } class_enum_failed: SysFreeString(wszCatName); SysFreeString(wszCatClsid); IPropertyBag_Release(pPropBag); pPropBag = NULL; } IEnumMoniker_Release(pMCat); pMCat = NULL; } out_show_filters: if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; } if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; } return hr; }
static GValueArray * gst_dshowaudiosrc_get_device_name_values (GstDshowAudioSrc * src) { GValueArray *array = g_value_array_new (0); GValue value = { 0 }; ICreateDevEnum *devices_enum = NULL; IEnumMoniker *moniker_enum = NULL; IMoniker *moniker = NULL; HRESULT hres = S_FALSE; ULONG fetched; g_value_init (&value, G_TYPE_STRING); hres = CoCreateInstance (&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, &IID_ICreateDevEnum, (void **) &devices_enum); if (hres != S_OK) { GST_CAT_ERROR (dshowaudiosrc_debug, "Can't create an instance of the system device enumerator (error=%d)", hres); array = NULL; goto clean; } hres = ICreateDevEnum_CreateClassEnumerator (devices_enum, &CLSID_AudioInputDeviceCategory, &moniker_enum, 0); if (hres != S_OK || !moniker_enum) { GST_CAT_ERROR (dshowaudiosrc_debug, "Can't get enumeration of audio devices (error=%d)", hres); array = NULL; goto clean; } IEnumMoniker_Reset (moniker_enum); while (hres = IEnumMoniker_Next (moniker_enum, 1, &moniker, &fetched), hres == S_OK) { IPropertyBag *property_bag = NULL; hres = IMoniker_BindToStorage (moniker, NULL, NULL, &IID_IPropertyBag, (void **) &property_bag); if (SUCCEEDED (hres) && property_bag) { VARIANT varFriendlyName; VariantInit (&varFriendlyName); hres = IPropertyBag_Read (property_bag, 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); g_value_set_string (&value, friendly_name); g_value_array_append (array, &value); g_value_unset (&value); g_free (friendly_name); SysFreeString (varFriendlyName.bstrVal); } IPropertyBag_Release (property_bag); } IMoniker_Release (moniker); } clean: if (moniker_enum) { IEnumMoniker_Release (moniker_enum); } if (devices_enum) { ICreateDevEnum_Release (devices_enum); } return array; }
static HRESULT download_url(InstallEngine *This, char *id, char *display, char *url, DWORD flags, DWORD dl_size) { struct downloadcb *callback = NULL; char *filename = NULL; IUnknown *unk = NULL; IMoniker *mon = NULL; IBindCtx *bindctx = NULL; HANDLE event = NULL; HRESULT hr; if (!This->downloaddir) { WARN("No download directory set\n"); return E_FAIL; } hr = generate_moniker(This->baseurl, url, flags, &mon); if (FAILED(hr)) { FIXME("Failed to create moniker\n"); return hr; } event = CreateEventW(NULL, TRUE, FALSE, NULL); if (!event) { IMoniker_Release(mon); return E_FAIL; } filename = strrchr(url, '/'); if (!filename) filename = url; filename = merge_path(This->downloaddir, filename); if (!filename) { hr = E_OUTOFMEMORY; goto error; } hr = downloadcb_create(This, event, filename, id, display, dl_size, &callback); if (FAILED(hr)) goto error; hr = CreateAsyncBindCtx(0, &callback->IBindStatusCallback_iface, NULL, &bindctx); if(FAILED(hr)) goto error; hr = IMoniker_BindToStorage(mon, bindctx, NULL, &IID_IUnknown, (void**)&unk); if (FAILED(hr)) goto error; if (unk) IUnknown_Release(unk); heap_free(filename); IMoniker_Release(mon); IBindCtx_Release(bindctx); WaitForSingleObject(event, INFINITE); hr = callback->hr; CloseHandle(event); IBindStatusCallback_Release(&callback->IBindStatusCallback_iface); return hr; error: if (mon) IMoniker_Release(mon); if (event) CloseHandle(event); if (callback) IBindStatusCallback_Release(&callback->IBindStatusCallback_iface); if (bindctx) IBindCtx_Release(bindctx); if (filename) heap_free(filename); return hr; }
static HRESULT WINAPI DEVENUM_IMediaCatMoniker_BindToObject(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft, REFIID riidResult, void **ppvResult) { MediaCatMoniker *This = impl_from_IMoniker(iface); IUnknown * pObj = NULL; IPropertyBag * pProp = NULL; CLSID clsID; VARIANT var; HRESULT res = E_FAIL; TRACE("(%p)->(%p, %p, %s, %p)\n", This, pbc, pmkToLeft, debugstr_guid(riidResult), ppvResult); VariantInit(&var); *ppvResult = NULL; if(pmkToLeft==NULL) { /* first activation of this class */ LPVOID pvptr; res=IMoniker_BindToStorage(iface, NULL, NULL, &IID_IPropertyBag, &pvptr); pProp = pvptr; if (SUCCEEDED(res)) { V_VT(&var) = VT_LPWSTR; res = IPropertyBag_Read(pProp, clsid_keyname, &var, NULL); } if (SUCCEEDED(res)) { res = CLSIDFromString(V_UNION(&var,bstrVal), &clsID); CoTaskMemFree(V_UNION(&var, bstrVal)); } if (SUCCEEDED(res)) { res=CoCreateInstance(&clsID,NULL,CLSCTX_ALL,&IID_IUnknown,&pvptr); pObj = pvptr; } } if (pObj!=NULL) { /* get the requested interface from the loaded class */ res = S_OK; if (pProp) { HRESULT res2; LPVOID ppv = NULL; res2 = IUnknown_QueryInterface(pObj, &IID_IPersistPropertyBag, &ppv); if (SUCCEEDED(res2)) { res = IPersistPropertyBag_Load((IPersistPropertyBag *) ppv, pProp, NULL); IPersistPropertyBag_Release((IPersistPropertyBag *) ppv); } } if (SUCCEEDED(res)) res= IUnknown_QueryInterface(pObj,riidResult,ppvResult); IUnknown_Release(pObj); } if (pProp) { IPropertyBag_Release(pProp); } TRACE("<- 0x%x\n", res); return res; }
static HRESULT WINAPI MkProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri, IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE *dwReserved) { MkProtocol *This = impl_from_IInternetProtocolEx(iface); LPWSTR mime, progid, display_name, colon_ptr; DWORD bindf=0, eaten=0, scheme=0, len; BSTR url, path = NULL; IParseDisplayName *pdn; BINDINFO bindinfo; STATSTG statstg; IMoniker *mon; HRESULT hres; CLSID clsid; TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink, pOIBindInfo, grfPI, dwReserved); hres = IUri_GetScheme(pUri, &scheme); if(FAILED(hres)) return hres; if(scheme != URL_SCHEME_MK) return INET_E_INVALID_URL; memset(&bindinfo, 0, sizeof(bindinfo)); bindinfo.cbSize = sizeof(BINDINFO); hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo); if(FAILED(hres)) { WARN("GetBindInfo failed: %08x\n", hres); return hres; } ReleaseBindInfo(&bindinfo); IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, NULL); hres = IUri_GetDisplayUri(pUri, &url); if(FAILED(hres)) return hres; hres = FindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0); SysFreeString(url); if(SUCCEEDED(hres)) { IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime); CoTaskMemFree(mime); } hres = IUri_GetPath(pUri, &path); if(FAILED(hres)) return hres; len = SysStringLen(path)+1; hres = UrlUnescapeW(path, NULL, &len, URL_UNESCAPE_INPLACE); if (FAILED(hres)) { SysFreeString(path); return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER); } progid = path+1; /* skip '@' symbol */ colon_ptr = strchrW(path, ':'); if(!colon_ptr) { SysFreeString(path); return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER); } len = strlenW(path); display_name = heap_alloc((len+1)*sizeof(WCHAR)); memcpy(display_name, path, (len+1)*sizeof(WCHAR)); progid[colon_ptr-progid] = 0; /* overwrite ':' with NULL terminator */ hres = CLSIDFromProgID(progid, &clsid); SysFreeString(path); if(FAILED(hres)) { heap_free(display_name); return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER); } hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IParseDisplayName, (void**)&pdn); if(FAILED(hres)) { WARN("Could not create object %s\n", debugstr_guid(&clsid)); heap_free(display_name); return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER); } hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon); heap_free(display_name); IParseDisplayName_Release(pdn); if(FAILED(hres)) { WARN("ParseDisplayName failed: %08x\n", hres); return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER); } if(This->stream) { IStream_Release(This->stream); This->stream = NULL; } hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream); IMoniker_Release(mon); if(FAILED(hres)) { WARN("BindToStorage failed: %08x\n", hres); return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER); } hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME); if(FAILED(hres)) { WARN("Stat failed: %08x\n", hres); return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER); } IInternetProtocolSink_ReportData(pOIProtSink, BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart); return report_result(pOIProtSink, S_OK, ERROR_SUCCESS); }