/* * SetupRegisterFilter through IFilterMapper2 */ static HRESULT SetupRegisterFilter2(const AMOVIESETUP_FILTER * const pSetup, IFilterMapper2 * pIFM2, BOOL bRegister) { HRESULT hr; if (NULL == pSetup) return S_FALSE; /* unregister filter */ hr = IFilterMapper2_UnregisterFilter(pIFM2, 0, 0, pSetup->clsID); if (bRegister) { REGFILTER2 rf2; rf2.dwVersion = 1; rf2.dwMerit = pSetup->dwMerit; rf2.u.s.cPins = pSetup->nPins; rf2.u.s.rgPins = pSetup->lpPin; /* register filter */ hr = IFilterMapper2_RegisterFilter(pIFM2, pSetup->clsID, pSetup->strName, 0, 0, NULL, &rf2); } else { /* filter not found is ignored here, but there is no #define for 0x80070002 */ if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) hr = NOERROR; } return hr; }
/*********************************************************************** * unregister_filters */ static HRESULT unregister_filters(struct regsvr_filter const *list) { HRESULT hr; IFilterMapper2* pFM2; CoInitialize(NULL); hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2); if (SUCCEEDED(hr)) { for (; SUCCEEDED(hr) && list->clsid; ++list) hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid); IFilterMapper2_Release(pFM2); } CoUninitialize(); return hr; }
HRESULT WINAPI AMovieSetupRegisterFilter2(const AMOVIESETUP_FILTER *pFilter, IFilterMapper2 *pIFM2, BOOL bRegister) { if (!pFilter) return S_OK; if (bRegister) { { REGFILTER2 rf2; rf2.dwVersion = 1; rf2.dwMerit = pFilter->merit; rf2.u.s1.cPins = pFilter->pins; rf2.u.s1.rgPins = pFilter->pPin; return IFilterMapper2_RegisterFilter(pIFM2, pFilter->clsid, pFilter->name, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rf2); } } else return IFilterMapper2_UnregisterFilter(pIFM2, &CLSID_LegacyAmFilterCategory, NULL, pFilter->clsid); }
static void test_fm2_enummatchingfilters(void) { IFilterMapper2 *pMapper = NULL; HRESULT hr; REGFILTER2 rgf2; REGFILTERPINS2 rgPins2[2]; REGPINTYPES rgPinType; static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 }; static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 }; CLSID clsidFilter1; CLSID clsidFilter2; IEnumMoniker *pEnum = NULL; BOOL found, registered = TRUE; ZeroMemory(&rgf2, sizeof(rgf2)); hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper); ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = CoCreateGuid(&clsidFilter1); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); hr = CoCreateGuid(&clsidFilter2); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); /* Test that a test renderer filter is returned when enumerating filters with bRender=FALSE */ rgf2.dwVersion = 2; rgf2.dwMerit = MERIT_UNLIKELY; S2(U(rgf2)).cPins2 = 1; S2(U(rgf2)).rgPins2 = rgPins2; rgPins2[0].dwFlags = REG_PINFLAG_B_RENDERER; rgPins2[0].cInstances = 1; rgPins2[0].nMediaTypes = 1; rgPins2[0].lpMediaType = &rgPinType; rgPins2[0].nMediums = 0; rgPins2[0].lpMedium = NULL; rgPins2[0].clsPinCategory = NULL; rgPinType.clsMajorType = &GUID_NULL; rgPinType.clsMinorType = &GUID_NULL; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); if (hr == E_ACCESSDENIED) { registered = FALSE; skip("Not authorized to register filters\n"); } else { ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); rgPins2[0].dwFlags = 0; rgPins2[1].dwFlags = REG_PINFLAG_B_OUTPUT; rgPins2[1].cInstances = 1; rgPins2[1].nMediaTypes = 1; rgPins2[1].lpMediaType = &rgPinType; rgPins2[1].nMediums = 0; rgPins2[1].lpMedium = NULL; rgPins2[1].clsPinCategory = NULL; S2(U(rgf2)).cPins2 = 2; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName1, pEnum); ok(found, "EnumMatchingFilters failed to return the test filter 1\n"); } if (pEnum) IEnumMoniker_Release(pEnum); pEnum = NULL; hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, FALSE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName2, pEnum); ok(found, "EnumMatchingFilters failed to return the test filter 2\n"); } if (pEnum) IEnumMoniker_Release(pEnum); pEnum = NULL; /* Non renderer must not be returned with bRender=TRUE */ hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName1, pEnum); ok(found, "EnumMatchingFilters failed to return the test filter 1\n"); } } if (pEnum) IEnumMoniker_Release(pEnum); pEnum = NULL; hr = IFilterMapper2_EnumMatchingFilters(pMapper, &pEnum, 0, TRUE, MERIT_UNLIKELY, TRUE, 0, NULL, NULL, &GUID_NULL, TRUE, FALSE, 0, NULL, NULL, &GUID_NULL); ok(hr == S_OK, "IFilterMapper2_EnumMatchingFilters failed with %x\n", hr); if (SUCCEEDED(hr) && pEnum) { found = enum_find_filter(wszFilterName2, pEnum); ok(!found, "EnumMatchingFilters should not return the test filter 2\n"); } if (registered) { hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1); ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr); hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2); ok(SUCCEEDED(hr), "IFilterMapper2_UnregisterFilter failed with %x\n", hr); } out: if (pEnum) IEnumMoniker_Release(pEnum); if (pMapper) IFilterMapper2_Release(pMapper); }
static void test_register_filter_with_null_clsMinorType(void) { IFilterMapper2 *pMapper = NULL; HRESULT hr; REGFILTER2 rgf2; REGFILTERPINS rgPins; REGFILTERPINS2 rgPins2; REGPINTYPES rgPinType; static WCHAR wszPinName[] = {'P', 'i', 'n', 0 }; static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 }; static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 }; CLSID clsidFilter1; CLSID clsidFilter2; hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper); ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = CoCreateGuid(&clsidFilter1); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); hr = CoCreateGuid(&clsidFilter2); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); rgPinType.clsMajorType = &GUID_NULL; /* Make sure quartz accepts it without crashing */ rgPinType.clsMinorType = NULL; /* Test with pin descript version 1 */ ZeroMemory(&rgf2, sizeof(rgf2)); rgf2.dwVersion = 1; rgf2.dwMerit = MERIT_UNLIKELY; S1(U(rgf2)).cPins = 1; S1(U(rgf2)).rgPins = &rgPins; rgPins.strName = wszPinName; rgPins.bRendered = 1; rgPins.bOutput = 0; rgPins.bZero = 0; rgPins.bMany = 0; rgPins.clsConnectsToFilter = NULL; rgPins.strConnectsToPin = NULL; rgPins.nMediaTypes = 1; rgPins.lpMediaType = &rgPinType; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); if (hr == E_ACCESSDENIED) { skip("Not authorized to register filters\n"); goto out; } ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); /* Test with pin descript version 2 */ ZeroMemory(&rgf2, sizeof(rgf2)); rgf2.dwVersion = 2; rgf2.dwMerit = MERIT_UNLIKELY; S2(U(rgf2)).cPins2 = 1; S2(U(rgf2)).rgPins2 = &rgPins2; rgPins2.dwFlags = REG_PINFLAG_B_RENDERER; rgPins2.cInstances = 1; rgPins2.nMediaTypes = 1; rgPins2.lpMediaType = &rgPinType; rgPins2.nMediums = 0; rgPins2.lpMedium = NULL; rgPins2.clsPinCategory = NULL; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); out: if (pMapper) IFilterMapper2_Release(pMapper); }