oleaut32: Fix parsing of hex numbers with 'e' in the string by moving
[wine/wine64.git] / dlls / quartz / filtermapper.c
blob5a5eaf34fc14370f788d6e003658e262841bae40
1 /*
2 * IFilterMapper & IFilterMapper2 Implementations
4 * Copyright 2003 Robert Shearman
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "quartz_private.h"
34 #define COM_NO_WINDOWS_H
35 #include "ole2.h"
36 #include "olectl.h"
37 #include "strmif.h"
38 #include "wine/unicode.h"
39 #include "uuids.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 typedef struct FilterMapper2Impl
47 const IFilterMapper2Vtbl *lpVtbl;
48 const IFilterMapperVtbl *lpVtblFilterMapper;
49 LONG refCount;
50 } FilterMapper2Impl;
52 static const IFilterMapper2Vtbl fm2vtbl;
53 static const IFilterMapperVtbl fmvtbl;
55 static inline FilterMapper2Impl *impl_from_IFilterMapper( IFilterMapper *iface )
57 return (FilterMapper2Impl *)((char*)iface - FIELD_OFFSET(FilterMapper2Impl, lpVtblFilterMapper));
60 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
61 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
62 static const WCHAR wszSlash[] = {'\\',0};
64 /* CLSID property in media category Moniker */
65 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
66 /* FriendlyName property in media category Moniker */
67 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
68 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
69 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
70 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
71 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
72 /* For filters registered with IFilterMapper */
73 static const WCHAR wszFilterSlash[] = {'F','i','l','t','e','r','\\',0};
74 static const WCHAR wszFilter[] = {'F','i','l','t','e','r',0};
75 /* For pins registered with IFilterMapper */
76 static const WCHAR wszPins[] = {'P','i','n','s',0};
77 static const WCHAR wszAllowedMany[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
78 static const WCHAR wszAllowedZero[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
79 static const WCHAR wszDirection[] = {'D','i','r','e','c','t','i','o','n',0};
80 static const WCHAR wszIsRendered[] = {'I','s','R','e','n','d','e','r','e','d',0};
81 /* For types registered with IFilterMapper */
82 static const WCHAR wszTypes[] = {'T','y','p','e','s',0};
85 /* registry format for REGFILTER2 */
86 struct REG_RF
88 DWORD dwVersion;
89 DWORD dwMerit;
90 DWORD dwPins;
91 DWORD dwUnused;
94 struct REG_RFP
96 BYTE signature[4]; /* e.g. "0pi3" */
97 DWORD dwFlags;
98 DWORD dwInstances;
99 DWORD dwMediaTypes;
100 DWORD dwMediums;
101 DWORD bCategory; /* is there a category clsid? */
102 /* optional: dwOffsetCategoryClsid */
105 struct REG_TYPE
107 BYTE signature[4]; /* e.g. "0ty3" */
108 DWORD dwUnused;
109 DWORD dwOffsetMajor;
110 DWORD dwOffsetMinor;
113 struct MONIKER_MERIT
115 IMoniker * pMoniker;
116 DWORD dwMerit;
119 struct Vector
121 LPBYTE pData;
122 int capacity; /* in bytes */
123 int current; /* pointer to next free byte */
126 /* returns the position it was added at */
127 static int add_data(struct Vector * v, const BYTE * pData, int size)
129 int index = v->current;
130 if (v->current + size > v->capacity)
132 LPBYTE pOldData = v->pData;
133 v->capacity = (v->capacity + size) * 2;
134 v->pData = CoTaskMemAlloc(v->capacity);
135 memcpy(v->pData, pOldData, v->current);
136 CoTaskMemFree(pOldData);
138 memcpy(v->pData + v->current, pData, size);
139 v->current += size;
140 return index;
143 static int find_data(struct Vector * v, const BYTE * pData, int size)
145 int index;
146 for (index = 0; index < v->current; index++)
147 if (!memcmp(v->pData + index, pData, size))
148 return index;
149 /* not found */
150 return -1;
153 static void delete_vector(struct Vector * v)
155 if (v->pData)
156 CoTaskMemFree(v->pData);
157 v->current = 0;
158 v->capacity = 0;
161 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
163 FilterMapper2Impl * pFM2impl;
165 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
167 if (pUnkOuter)
168 return CLASS_E_NOAGGREGATION;
170 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
171 if (!pFM2impl)
172 return E_OUTOFMEMORY;
174 pFM2impl->lpVtbl = &fm2vtbl;
175 pFM2impl->lpVtblFilterMapper = &fmvtbl;
176 pFM2impl->refCount = 1;
178 *ppObj = pFM2impl;
180 TRACE("-- created at %p\n", pFM2impl);
182 return S_OK;
185 /*** IUnknown methods ***/
187 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
189 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
191 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
193 *ppv = NULL;
195 if (IsEqualIID(riid, &IID_IUnknown))
196 *ppv = iface;
197 else if (IsEqualIID(riid, &IID_IFilterMapper2))
198 *ppv = iface;
199 else if (IsEqualIID(riid, &IID_IFilterMapper))
200 *ppv = &This->lpVtblFilterMapper;
202 if (*ppv != NULL)
204 IUnknown_AddRef((IUnknown *)*ppv);
205 return S_OK;
208 FIXME("No interface for %s\n", debugstr_guid(riid));
209 return E_NOINTERFACE;
212 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
214 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
215 ULONG refCount = InterlockedIncrement(&This->refCount);
217 TRACE("(%p)->()\n", iface);
219 return refCount;
222 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
224 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
225 ULONG refCount = InterlockedDecrement(&This->refCount);
227 TRACE("(%p)->()\n", iface);
229 if (refCount == 0)
231 CoTaskMemFree(This);
232 return 0;
234 return refCount;
237 /*** IFilterMapper2 methods ***/
239 static HRESULT WINAPI FilterMapper2_CreateCategory(
240 IFilterMapper2 * iface,
241 REFCLSID clsidCategory,
242 DWORD dwCategoryMerit,
243 LPCWSTR szDescription)
245 LPWSTR wClsidAMCat = NULL;
246 LPWSTR wClsidCategory = NULL;
247 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
248 HKEY hKey = NULL;
249 LONG lRet;
250 HRESULT hr;
252 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
254 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
256 if (SUCCEEDED(hr))
258 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
261 if (SUCCEEDED(hr))
263 strcpyW(wszKeyName, wszClsidSlash);
264 strcatW(wszKeyName, wClsidAMCat);
265 strcatW(wszKeyName, wszSlashInstance);
266 strcatW(wszKeyName, wClsidCategory);
268 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
269 hr = HRESULT_FROM_WIN32(lRet);
272 if (SUCCEEDED(hr))
274 lRet = RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (const BYTE*)szDescription, (strlenW(szDescription) + 1) * sizeof(WCHAR));
275 hr = HRESULT_FROM_WIN32(lRet);
278 if (SUCCEEDED(hr))
280 lRet = RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, (strlenW(wClsidCategory) + 1) * sizeof(WCHAR));
281 hr = HRESULT_FROM_WIN32(lRet);
284 if (SUCCEEDED(hr))
286 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit));
287 hr = HRESULT_FROM_WIN32(lRet);
290 CloseHandle(hKey);
292 if (wClsidCategory)
293 CoTaskMemFree(wClsidCategory);
294 if (wClsidAMCat)
295 CoTaskMemFree(wClsidAMCat);
297 return hr;
300 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
301 IFilterMapper2 * iface,
302 const CLSID *pclsidCategory,
303 const OLECHAR *szInstance,
304 REFCLSID Filter)
306 WCHAR wszKeyName[MAX_PATH];
307 LPWSTR wClsidCategory = NULL;
308 LPWSTR wFilter = NULL;
309 HRESULT hr;
311 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
313 if (!pclsidCategory)
314 pclsidCategory = &CLSID_LegacyAmFilterCategory;
316 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
318 if (SUCCEEDED(hr))
320 strcpyW(wszKeyName, wszClsidSlash);
321 strcatW(wszKeyName, wClsidCategory);
322 strcatW(wszKeyName, wszSlashInstance);
323 if (szInstance)
324 strcatW(wszKeyName, szInstance);
325 else
327 hr = StringFromCLSID(Filter, &wFilter);
328 if (SUCCEEDED(hr))
329 strcatW(wszKeyName, wFilter);
333 if (SUCCEEDED(hr))
335 LONG lRet = RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName);
336 hr = HRESULT_FROM_WIN32(lRet);
339 if (wClsidCategory)
340 CoTaskMemFree(wClsidCategory);
341 if (wFilter)
342 CoTaskMemFree(wFilter);
344 return hr;
347 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
349 VARIANT var;
351 V_VT(&var) = VT_BSTR;
352 V_UNION(&var, bstrVal) = (BSTR)szName;
354 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
357 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
359 LPWSTR wszClsid = NULL;
360 VARIANT var;
361 HRESULT hr;
363 hr = StringFromCLSID(clsid, &wszClsid);
365 if (SUCCEEDED(hr))
367 V_VT(&var) = VT_BSTR;
368 V_UNION(&var, bstrVal) = wszClsid;
369 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
371 if (wszClsid)
372 CoTaskMemFree(wszClsid);
373 return hr;
376 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
378 VARIANT var;
379 int size = sizeof(struct REG_RF);
380 unsigned int i;
381 struct Vector mainStore = {NULL, 0, 0};
382 struct Vector clsidStore = {NULL, 0, 0};
383 struct REG_RF rrf;
384 SAFEARRAY * psa;
385 SAFEARRAYBOUND saBound;
386 HRESULT hr = S_OK;
388 rrf.dwVersion = prf2->dwVersion;
389 rrf.dwMerit = prf2->dwMerit;
390 rrf.dwPins = prf2->u.s1.cPins2;
391 rrf.dwUnused = 0;
393 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
395 for (i = 0; i < prf2->u.s1.cPins2; i++)
397 size += sizeof(struct REG_RFP);
398 if (prf2->u.s1.rgPins2[i].clsPinCategory)
399 size += sizeof(DWORD);
400 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
401 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
404 for (i = 0; i < prf2->u.s1.cPins2; i++)
406 struct REG_RFP rrfp;
407 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
408 unsigned int j;
410 rrfp.signature[0] = '0';
411 rrfp.signature[1] = 'p';
412 rrfp.signature[2] = 'i';
413 rrfp.signature[3] = '3';
414 rrfp.signature[0] += i;
415 rrfp.dwFlags = rgPin2.dwFlags;
416 rrfp.dwInstances = rgPin2.cInstances;
417 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
418 rrfp.dwMediums = rgPin2.nMediums;
419 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
421 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
422 if (rrfp.bCategory)
424 DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
425 if (index == -1)
426 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
427 index += size;
429 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
432 for (j = 0; j < rgPin2.nMediaTypes; j++)
434 struct REG_TYPE rt;
435 rt.signature[0] = '0';
436 rt.signature[1] = 't';
437 rt.signature[2] = 'y';
438 rt.signature[3] = '3';
439 rt.signature[0] += j;
441 rt.dwUnused = 0;
442 rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
443 if (rt.dwOffsetMajor == -1)
444 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
445 rt.dwOffsetMajor += size;
446 rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
447 if (rt.dwOffsetMinor == -1)
448 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
449 rt.dwOffsetMinor += size;
451 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
454 for (j = 0; j < rgPin2.nMediums; j++)
456 DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
457 if (index == -1)
458 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
459 index += size;
461 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
465 saBound.lLbound = 0;
466 saBound.cElements = mainStore.current + clsidStore.current;
467 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
468 if (!psa)
470 ERR("Couldn't create SAFEARRAY\n");
471 hr = E_FAIL;
474 if (SUCCEEDED(hr))
476 LPBYTE pbSAData;
477 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
478 if (SUCCEEDED(hr))
480 memcpy(pbSAData, mainStore.pData, mainStore.current);
481 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
482 hr = SafeArrayUnaccessData(psa);
486 V_VT(&var) = VT_ARRAY | VT_UI1;
487 V_UNION(&var, parray) = psa;
489 if (SUCCEEDED(hr))
490 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
492 if (psa)
493 SafeArrayDestroy(psa);
495 delete_vector(&mainStore);
496 delete_vector(&clsidStore);
497 return hr;
500 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
502 VARIANT var;
503 HRESULT hr;
504 LPBYTE pData = NULL;
505 struct REG_RF * prrf;
506 LPBYTE pCurrent;
507 DWORD i;
508 REGFILTERPINS2 * rgPins2;
510 VariantInit(&var);
511 V_VT(&var) = VT_ARRAY | VT_UI1;
513 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
515 if (SUCCEEDED(hr))
516 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
518 if (SUCCEEDED(hr))
520 prrf = (struct REG_RF *)pData;
521 pCurrent = pData;
523 if (prrf->dwVersion != 2)
525 FIXME("Filter registry version %ld not supported\n", prrf->dwVersion);
526 ZeroMemory(prf2, sizeof(*prf2));
527 hr = E_FAIL;
531 if (SUCCEEDED(hr))
533 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
534 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
536 prf2->dwVersion = prrf->dwVersion;
537 prf2->dwMerit = prrf->dwMerit;
538 prf2->u.s1.cPins2 = prrf->dwPins;
539 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
540 prf2->u.s1.rgPins2 = rgPins2;
541 pCurrent += sizeof(struct REG_RF);
543 for (i = 0; i < prrf->dwPins; i++)
545 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
546 REGPINTYPES * lpMediaType;
547 REGPINMEDIUM * lpMedium;
548 UINT j;
550 /* FIXME: check signature */
552 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp->signature, 4));
554 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
555 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
557 rgPins2[i].dwFlags = prrfp->dwFlags;
558 rgPins2[i].cInstances = prrfp->dwInstances;
559 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
560 rgPins2[i].nMediums = prrfp->dwMediums;
561 pCurrent += sizeof(struct REG_RFP);
562 if (prrfp->bCategory)
564 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
565 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
566 pCurrent += sizeof(DWORD);
567 rgPins2[i].clsPinCategory = clsCat;
569 else
570 rgPins2[i].clsPinCategory = NULL;
572 if (rgPins2[i].nMediaTypes > 0)
573 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
574 else
575 lpMediaType = NULL;
577 rgPins2[i].lpMediaType = lpMediaType;
579 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
581 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
582 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
583 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
585 /* FIXME: check signature */
586 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt->signature, 4));
588 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
589 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
591 lpMediaType[j].clsMajorType = clsMajor;
592 lpMediaType[j].clsMinorType = clsMinor;
594 pCurrent += sizeof(*prt);
597 if (rgPins2[i].nMediums > 0)
598 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
599 else
600 lpMedium = NULL;
602 rgPins2[i].lpMedium = lpMedium;
604 for (j = 0; j < rgPins2[i].nMediums; j++)
606 DWORD dwOffset = *(DWORD *)pCurrent;
608 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
610 pCurrent += sizeof(dwOffset);
616 if (pData)
617 SafeArrayUnaccessData(V_UNION(&var, parray));
619 VariantClear(&var);
621 return hr;
624 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
626 UINT i;
627 for (i = 0; i < prf2->u.s1.cPins2; i++)
629 UINT j;
630 if (prf2->u.s1.rgPins2[i].clsPinCategory)
631 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
633 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
635 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
636 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
638 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
642 static HRESULT WINAPI FilterMapper2_RegisterFilter(
643 IFilterMapper2 * iface,
644 REFCLSID clsidFilter,
645 LPCWSTR szName,
646 IMoniker **ppMoniker,
647 const CLSID *pclsidCategory,
648 const OLECHAR *szInstance,
649 const REGFILTER2 *prf2)
651 IParseDisplayName * pParser = NULL;
652 IBindCtx * pBindCtx = NULL;
653 IMoniker * pMoniker = NULL;
654 IPropertyBag * pPropBag = NULL;
655 HRESULT hr;
656 LPWSTR pwszParseName = NULL;
657 LPWSTR pCurrent;
658 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
659 int nameLen;
660 ULONG ulEaten;
661 LPWSTR szClsidTemp = NULL;
662 REGFILTER2 regfilter2;
663 REGFILTERPINS2* pregfp2 = NULL;
665 TRACE("(%s, %s, %p, %s, %s, %p)\n",
666 debugstr_guid(clsidFilter),
667 debugstr_w(szName),
668 ppMoniker,
669 debugstr_guid(pclsidCategory),
670 debugstr_w(szInstance),
671 prf2);
673 if (prf2->dwVersion == 2)
675 regfilter2 = *prf2;
677 else if (prf2->dwVersion == 1)
679 ULONG i;
680 DWORD flags;
681 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
682 regfilter2.dwVersion = 2;
683 regfilter2.dwMerit = prf2->dwMerit;
684 regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
685 pregfp2 = (REGFILTERPINS2*) CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
686 regfilter2.u.s1.rgPins2 = pregfp2;
687 for (i = 0; i < prf2->u.s.cPins; i++)
689 flags = 0;
690 if (prf2->u.s.rgPins[i].bRendered)
691 flags |= REG_PINFLAG_B_RENDERER;
692 if (prf2->u.s.rgPins[i].bOutput)
693 flags |= REG_PINFLAG_B_OUTPUT;
694 if (prf2->u.s.rgPins[i].bZero)
695 flags |= REG_PINFLAG_B_ZERO;
696 if (prf2->u.s.rgPins[i].bMany)
697 flags |= REG_PINFLAG_B_MANY;
698 pregfp2[i].dwFlags = flags;
699 pregfp2[i].cInstances = 1;
700 pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
701 pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
702 pregfp2[i].nMediums = 0;
703 pregfp2[i].lpMedium = NULL;
704 pregfp2[i].clsPinCategory = NULL;
707 else
709 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
710 return E_NOTIMPL;
713 if (ppMoniker)
714 *ppMoniker = NULL;
716 if (!pclsidCategory)
717 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
718 * In fact this is the CLSID_LegacyAmFilterCategory one */
719 pclsidCategory = &CLSID_LegacyAmFilterCategory;
721 /* sizeof... will include the null terminator and
722 * the + 1 is for the separator ('\\'). The -1 is
723 * because CHARS_IN_GUID includes the null terminator
725 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
727 if (szInstance)
728 nameLen += strlenW(szInstance);
729 else
730 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
732 pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
733 if (!pwszParseName)
734 return E_OUTOFMEMORY;
736 strcpyW(pwszParseName, wszDevice);
737 pCurrent += strlenW(wszDevice);
739 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
741 if (SUCCEEDED(hr))
743 memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
744 pCurrent += CHARS_IN_GUID - 1;
745 pCurrent[0] = '\\';
747 if (szInstance)
748 strcpyW(pCurrent+1, szInstance);
749 else
751 if (szClsidTemp)
753 CoTaskMemFree(szClsidTemp);
754 szClsidTemp = NULL;
756 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
757 if (SUCCEEDED(hr))
758 strcpyW(pCurrent+1, szClsidTemp);
762 if (SUCCEEDED(hr))
763 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
765 if (SUCCEEDED(hr))
766 hr = CreateBindCtx(0, &pBindCtx);
768 if (SUCCEEDED(hr))
769 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
771 if (pBindCtx)
772 IBindCtx_Release(pBindCtx);
773 if (pParser)
774 IParseDisplayName_Release(pParser);
776 if (SUCCEEDED(hr))
777 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
779 if (SUCCEEDED(hr))
780 hr = FM2_WriteFriendlyName(pPropBag, szName);
782 if (SUCCEEDED(hr))
783 hr = FM2_WriteClsid(pPropBag, clsidFilter);
785 if (SUCCEEDED(hr))
786 hr = FM2_WriteFilterData(pPropBag, &regfilter2);
788 if (pPropBag)
789 IPropertyBag_Release(pPropBag);
790 if (szClsidTemp)
791 CoTaskMemFree(szClsidTemp);
793 if (SUCCEEDED(hr) && ppMoniker)
794 *ppMoniker = pMoniker;
795 else if (pMoniker)
796 IMoniker_Release(pMoniker);
798 if (pregfp2)
799 CoTaskMemFree(pregfp2);
801 TRACE("-- returning %lx\n", hr);
803 return hr;
806 /* internal helper function */
807 static BOOL MatchTypes(
808 BOOL bExactMatch,
809 DWORD nPinTypes,
810 const REGPINTYPES * pPinTypes,
811 DWORD nMatchTypes,
812 const GUID * pMatchTypes)
814 BOOL bMatch = FALSE;
815 DWORD j;
817 if ((nMatchTypes == 0) && (nPinTypes > 0))
818 bMatch = TRUE;
820 for (j = 0; j < nPinTypes; j++)
822 DWORD i;
823 for (i = 0; i < nMatchTypes*2; i+=2)
825 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
826 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
828 bMatch = TRUE;
829 break;
833 return bMatch;
836 /* internal helper function for qsort of MONIKER_MERIT array */
837 static int mm_compare(const void * left, const void * right)
839 const struct MONIKER_MERIT * mmLeft = (const struct MONIKER_MERIT *)left;
840 const struct MONIKER_MERIT * mmRight = (const struct MONIKER_MERIT *)right;
842 if (mmLeft->dwMerit == mmRight->dwMerit)
843 return 0;
844 if (mmLeft->dwMerit > mmRight->dwMerit)
845 return -1;
846 return 1;
849 /* NOTES:
850 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
851 * (GUID_NULL's in input to function automatically treated as wild cards)
852 * Input/Output needed means match only on criteria if TRUE (with zero input types
853 * meaning match any input/output pin as long as one exists), otherwise match any
854 * filter that meets the rest of the requirements.
856 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
857 IFilterMapper2 * iface,
858 IEnumMoniker **ppEnum,
859 DWORD dwFlags,
860 BOOL bExactMatch,
861 DWORD dwMerit,
862 BOOL bInputNeeded,
863 DWORD cInputTypes,
864 const GUID *pInputTypes,
865 const REGPINMEDIUM *pMedIn,
866 const CLSID *pPinCategoryIn,
867 BOOL bRender,
868 BOOL bOutputNeeded,
869 DWORD cOutputTypes,
870 const GUID *pOutputTypes,
871 const REGPINMEDIUM *pMedOut,
872 const CLSID *pPinCategoryOut)
874 ICreateDevEnum * pCreateDevEnum;
875 IMoniker * pMonikerCat;
876 IEnumMoniker * pEnumCat;
877 HRESULT hr;
878 struct Vector monikers = {NULL, 0, 0};
880 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
881 ppEnum,
882 dwFlags,
883 bExactMatch ? "true" : "false",
884 dwMerit,
885 bInputNeeded ? "true" : "false",
886 cInputTypes,
887 pInputTypes,
888 pMedIn,
889 pPinCategoryIn,
890 bRender ? "true" : "false",
891 bOutputNeeded ? "true" : "false",
892 pOutputTypes,
893 pMedOut,
894 pPinCategoryOut);
896 if (dwFlags != 0)
898 FIXME("dwFlags = %lx not implemented\n", dwFlags);
901 *ppEnum = NULL;
903 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
905 if (SUCCEEDED(hr))
906 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
908 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
910 IPropertyBag * pPropBagCat = NULL;
911 VARIANT var;
912 HRESULT hrSub; /* this is so that one buggy filter
913 doesn't make the whole lot fail */
915 VariantInit(&var);
917 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
919 if (SUCCEEDED(hrSub))
920 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
922 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
924 CLSID clsidCat;
925 IEnumMoniker * pEnum;
926 IMoniker * pMoniker;
928 VariantClear(&var);
930 if (TRACE_ON(quartz))
932 VARIANT temp;
933 V_VT(&temp) = VT_EMPTY;
934 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
935 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
936 VariantClear(&temp);
939 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
941 if (SUCCEEDED(hrSub))
942 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
944 if (SUCCEEDED(hrSub))
945 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
947 if (hrSub == S_OK)
949 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
951 IPropertyBag * pPropBag = NULL;
952 REGFILTER2 rf2;
953 DWORD i;
954 BOOL bInputMatch = !bInputNeeded;
955 BOOL bOutputMatch = !bOutputNeeded;
957 ZeroMemory(&rf2, sizeof(rf2));
959 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
961 if (TRACE_ON(quartz))
963 VARIANT temp;
964 V_VT(&temp) = VT_EMPTY;
965 IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
966 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
967 VariantClear(&temp);
970 if (SUCCEEDED(hrSub))
971 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
973 /* Logic used for bInputMatch expression:
974 * There exists some pin such that bInputNeeded implies (pin is an input and
975 * (bRender implies pin has render flag) and major/minor types members of
976 * pInputTypes )
977 * bOutputMatch is similar, but without the "bRender implies ..." part
978 * and substituting variables names containing input for output
981 /* determine whether filter meets requirements */
982 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
984 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
986 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
988 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
989 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
990 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
991 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
992 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
995 if (bInputMatch && bOutputMatch)
997 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
998 IMoniker_AddRef(pMoniker);
999 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
1003 FM2_DeleteRegFilter(&rf2);
1004 if (pPropBag)
1005 IPropertyBag_Release(pPropBag);
1006 IMoniker_Release(pMoniker);
1008 IEnumMoniker_Release(pEnum);
1012 VariantClear(&var);
1013 if (pPropBagCat)
1014 IPropertyBag_Release(pPropBagCat);
1015 IMoniker_Release(pMonikerCat);
1018 if (SUCCEEDED(hr))
1020 IMoniker ** ppMoniker;
1021 unsigned int i;
1022 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1024 /* sort the monikers in descending merit order */
1025 qsort(monikers.pData, nMonikerCount,
1026 sizeof(struct MONIKER_MERIT),
1027 mm_compare);
1029 /* construct an IEnumMoniker interface */
1030 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1031 for (i = 0; i < nMonikerCount; i++)
1033 /* no need to AddRef here as already AddRef'd above */
1034 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1036 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1037 CoTaskMemFree(ppMoniker);
1040 delete_vector(&monikers);
1041 IEnumMoniker_Release(pEnumCat);
1042 ICreateDevEnum_Release(pCreateDevEnum);
1044 return hr;
1047 static const IFilterMapper2Vtbl fm2vtbl =
1050 FilterMapper2_QueryInterface,
1051 FilterMapper2_AddRef,
1052 FilterMapper2_Release,
1054 FilterMapper2_CreateCategory,
1055 FilterMapper2_UnregisterFilter,
1056 FilterMapper2_RegisterFilter,
1057 FilterMapper2_EnumMatchingFilters
1060 /*** IUnknown methods ***/
1062 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1064 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1066 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1068 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1071 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1073 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1075 return FilterMapper2_AddRef((IFilterMapper2*)This);
1078 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1080 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1082 return FilterMapper2_Release((IFilterMapper2*)This);
1085 /*** IFilterMapper methods ***/
1087 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1088 IFilterMapper * iface,
1089 IEnumRegFilters **ppEnum,
1090 DWORD dwMerit,
1091 BOOL bInputNeeded,
1092 CLSID clsInMaj,
1093 CLSID clsInSub,
1094 BOOL bRender,
1095 BOOL bOutputNeeded,
1096 CLSID clsOutMaj,
1097 CLSID clsOutSub)
1099 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1100 GUID InputType[2];
1101 GUID OutputType[2];
1102 IEnumMoniker* ppEnumMoniker;
1103 IMoniker* IMon;
1104 ULONG nb;
1105 ULONG idx = 0, nb_mon = 0;
1106 REGFILTER* regfilters;
1107 HRESULT hr;
1109 TRACE("(%p/%p)->(%p, %lx, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1110 iface,This,
1111 ppEnum,
1112 dwMerit,
1113 bInputNeeded ? "true" : "false",
1114 debugstr_guid(&clsInMaj),
1115 debugstr_guid(&clsInSub),
1116 bRender ? "true" : "false",
1117 bOutputNeeded ? "true" : "false",
1118 debugstr_guid(&clsOutMaj),
1119 debugstr_guid(&clsOutSub));
1121 InputType[0] = clsInMaj;
1122 InputType[1] = clsInSub;
1123 OutputType[0] = clsOutMaj;
1124 OutputType[1] = clsOutSub;
1126 hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1127 &ppEnumMoniker,
1129 TRUE,
1130 dwMerit,
1131 bInputNeeded,
1133 InputType,
1134 NULL,
1135 &GUID_NULL,
1136 bRender,
1137 bOutputNeeded,
1139 OutputType,
1140 NULL,
1141 &GUID_NULL);
1143 if (!SUCCEEDED(hr))
1144 return hr;
1146 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1148 IMoniker_Release(IMon);
1149 nb_mon++;
1152 *ppEnum = NULL;
1153 if (!nb_mon)
1155 IEnumMoniker_Release(ppEnumMoniker);
1156 return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1159 regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1160 if (!regfilters)
1162 IEnumMoniker_Release(ppEnumMoniker);
1163 return E_OUTOFMEMORY;
1166 IEnumMoniker_Reset(ppEnumMoniker);
1167 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1169 IPropertyBag * pPropBagCat = NULL;
1170 VARIANT var;
1171 HRESULT hrSub;
1172 GUID clsid;
1173 int len;
1175 VariantInit(&var);
1176 V_VT(&var) = VT_BSTR;
1178 hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1180 if (SUCCEEDED(hrSub))
1181 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1183 if (SUCCEEDED(hrSub))
1184 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1186 if (SUCCEEDED(hrSub))
1187 hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1189 if (SUCCEEDED(hrSub))
1191 len = (strlenW((WCHAR*)&V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1192 if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1193 hr = E_OUTOFMEMORY;
1196 if (SUCCEEDED(hrSub))
1198 memcpy(regfilters[idx].Name, &V_UNION(&var, bstrVal), len);
1199 regfilters[idx].Clsid = clsid;
1200 idx++;
1203 if (pPropBagCat)
1204 IPropertyBag_Release(pPropBagCat);
1205 IMoniker_Release(IMon);
1208 /* In case of release all resources */
1209 if (!SUCCEEDED(hr))
1211 for (idx = 0; idx < nb_mon; idx++)
1212 CoTaskMemFree(regfilters[idx].Name);
1213 CoTaskMemFree(regfilters);
1214 IEnumMoniker_Release(ppEnumMoniker);
1215 return hr;
1218 hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1219 CoTaskMemFree(regfilters);
1220 IEnumMoniker_Release(ppEnumMoniker);
1222 return hr;
1226 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1228 HRESULT hr;
1229 LPWSTR wszClsid = NULL;
1230 HKEY hKey;
1231 LONG lRet;
1232 WCHAR wszKeyName[strlenW(wszFilterSlash) + (CHARS_IN_GUID-1) + 1];
1234 TRACE("(%p)->(%s, %s, %lx)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1236 hr = StringFromCLSID(&clsid, &wszClsid);
1238 if (SUCCEEDED(hr))
1240 strcpyW(wszKeyName, wszFilterSlash);
1241 strcatW(wszKeyName, wszClsid);
1243 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1244 hr = HRESULT_FROM_WIN32(lRet);
1247 if (SUCCEEDED(hr))
1249 lRet = RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, strlenW(szName) + 1);
1250 hr = HRESULT_FROM_WIN32(lRet);
1251 CloseHandle(hKey);
1254 if (SUCCEEDED(hr))
1256 strcpyW(wszKeyName, wszClsidSlash);
1257 strcatW(wszKeyName, wszClsid);
1259 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1260 hr = HRESULT_FROM_WIN32(lRet);
1263 if (SUCCEEDED(hr))
1265 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit));
1266 hr = HRESULT_FROM_WIN32(lRet);
1267 CloseHandle(hKey);
1270 return hr;
1273 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1275 TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1277 /* Not implemented in Windows (tested on Win2k) */
1279 return E_NOTIMPL;
1282 static HRESULT WINAPI FilterMapper_RegisterPin(
1283 IFilterMapper * iface,
1284 CLSID Filter,
1285 LPCWSTR szName,
1286 BOOL bRendered,
1287 BOOL bOutput,
1288 BOOL bZero,
1289 BOOL bMany,
1290 CLSID ConnectsToFilter,
1291 LPCWSTR ConnectsToPin)
1293 HRESULT hr;
1294 LONG lRet;
1295 LPWSTR wszClsid = NULL;
1296 HKEY hKey = NULL;
1297 HKEY hPinsKey = NULL;
1298 WCHAR * wszPinsKeyName;
1299 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1301 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1302 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1304 hr = StringFromCLSID(&Filter, &wszClsid);
1306 if (SUCCEEDED(hr))
1308 strcpyW(wszKeyName, wszClsidSlash);
1309 strcatW(wszKeyName, wszClsid);
1311 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1312 hr = HRESULT_FROM_WIN32(lRet);
1315 if (SUCCEEDED(hr))
1317 wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1318 if (!wszPinsKeyName)
1319 hr = E_OUTOFMEMORY;
1322 if (SUCCEEDED(hr))
1324 strcpyW(wszPinsKeyName, wszPins);
1325 strcatW(wszPinsKeyName, wszSlash);
1326 strcatW(wszPinsKeyName, szName);
1328 lRet = RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL);
1329 hr = HRESULT_FROM_WIN32(lRet);
1330 CoTaskMemFree(wszPinsKeyName);
1333 if (SUCCEEDED(hr))
1335 lRet = RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany));
1336 hr = HRESULT_FROM_WIN32(lRet);
1339 if (SUCCEEDED(hr))
1341 lRet = RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero));
1342 hr = HRESULT_FROM_WIN32(lRet);
1345 if (SUCCEEDED(hr))
1347 lRet = RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput));
1348 hr = HRESULT_FROM_WIN32(lRet);
1351 if (SUCCEEDED(hr))
1353 lRet = RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered));
1354 hr = HRESULT_FROM_WIN32(lRet);
1357 if (SUCCEEDED(hr))
1359 lRet = RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL);
1360 hr = HRESULT_FROM_WIN32(lRet);
1363 if (wszClsid)
1364 CoTaskMemFree(wszClsid);
1365 if (hKey)
1366 CloseHandle(hKey);
1367 if (hPinsKey)
1368 CloseHandle(hPinsKey);
1370 return hr;
1374 static HRESULT WINAPI FilterMapper_RegisterPinType(
1375 IFilterMapper * iface,
1376 CLSID clsFilter,
1377 LPCWSTR szName,
1378 CLSID clsMajorType,
1379 CLSID clsSubType)
1381 HRESULT hr;
1382 LONG lRet;
1383 LPWSTR wszClsid = NULL;
1384 LPWSTR wszClsidMajorType = NULL;
1385 LPWSTR wszClsidSubType = NULL;
1386 HKEY hKey = NULL;
1387 WCHAR * wszTypesKey;
1388 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1390 TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1391 debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1393 hr = StringFromCLSID(&clsFilter, &wszClsid);
1395 if (SUCCEEDED(hr))
1397 hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1400 if (SUCCEEDED(hr))
1402 hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1405 if (SUCCEEDED(hr))
1407 wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1408 strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1409 if (!wszTypesKey)
1410 hr = E_OUTOFMEMORY;
1413 if (SUCCEEDED(hr))
1415 strcpyW(wszTypesKey, wszClsidSlash);
1416 strcatW(wszTypesKey, wszClsid);
1417 strcatW(wszTypesKey, wszSlash);
1418 strcatW(wszTypesKey, wszPins);
1419 strcatW(wszTypesKey, wszSlash);
1420 strcatW(wszTypesKey, szName);
1421 strcatW(wszTypesKey, wszSlash);
1422 strcatW(wszTypesKey, wszTypes);
1424 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey);
1425 hr = HRESULT_FROM_WIN32(lRet);
1426 CoTaskMemFree(wszTypesKey);
1429 if (SUCCEEDED(hr))
1431 strcpyW(wszKeyName, wszClsidMajorType);
1432 strcatW(wszKeyName, wszSlash);
1433 strcatW(wszKeyName, wszClsidSubType);
1435 lRet = RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL);
1436 hr = HRESULT_FROM_WIN32(lRet);
1437 CloseHandle(hKey);
1440 if (wszClsid)
1441 CoTaskMemFree(wszClsid);
1442 if (wszClsidMajorType)
1443 CoTaskMemFree(wszClsidMajorType);
1444 if (wszClsidSubType)
1445 CoTaskMemFree(wszClsidSubType);
1447 return hr;
1450 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1452 HRESULT hr;
1453 LONG lRet;
1454 LPWSTR wszClsid = NULL;
1455 HKEY hKey;
1456 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1458 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1460 hr = StringFromCLSID(&Filter, &wszClsid);
1462 if (SUCCEEDED(hr))
1464 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey);
1465 hr = HRESULT_FROM_WIN32(lRet);
1468 if (SUCCEEDED(hr))
1470 lRet = RegDeleteKeyW(hKey, wszClsid);
1471 hr = HRESULT_FROM_WIN32(lRet);
1472 CloseHandle(hKey);
1475 if (SUCCEEDED(hr))
1477 strcpyW(wszKeyName, wszClsidSlash);
1478 strcatW(wszKeyName, wszClsid);
1480 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1481 hr = HRESULT_FROM_WIN32(lRet);
1484 if (SUCCEEDED(hr))
1486 lRet = RegDeleteKeyW(hKey, wszMeritName);
1487 hr = HRESULT_FROM_WIN32(lRet);
1488 CloseHandle(hKey);
1491 if (wszClsid)
1492 CoTaskMemFree(wszClsid);
1494 return hr;
1497 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1499 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1501 /* Not implemented in Windows (tested on Win2k) */
1503 return E_NOTIMPL;
1506 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1508 HRESULT hr;
1509 LONG lRet;
1510 LPWSTR wszClsid = NULL;
1511 HKEY hKey = NULL;
1512 WCHAR * wszPinNameKey;
1513 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1515 TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1517 if (!Name)
1518 return E_INVALIDARG;
1520 hr = StringFromCLSID(&Filter, &wszClsid);
1522 if (SUCCEEDED(hr))
1524 strcpyW(wszKeyName, wszClsidSlash);
1525 strcatW(wszKeyName, wszClsid);
1527 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1528 hr = HRESULT_FROM_WIN32(lRet);
1531 if (SUCCEEDED(hr))
1533 wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1534 if (!wszPinNameKey)
1535 hr = E_OUTOFMEMORY;
1538 if (SUCCEEDED(hr))
1540 strcpyW(wszPinNameKey, wszPins);
1541 strcatW(wszPinNameKey, wszSlash);
1542 strcatW(wszPinNameKey, Name);
1544 lRet = RegDeleteKeyW(hKey, wszPinNameKey);
1545 hr = HRESULT_FROM_WIN32(lRet);
1546 CoTaskMemFree(wszPinNameKey);
1549 if (wszClsid)
1550 CoTaskMemFree(wszClsid);
1551 if (hKey)
1552 CloseHandle(hKey);
1554 return hr;
1557 static const IFilterMapperVtbl fmvtbl =
1560 FilterMapper_QueryInterface,
1561 FilterMapper_AddRef,
1562 FilterMapper_Release,
1564 FilterMapper_RegisterFilter,
1565 FilterMapper_RegisterFilterInstance,
1566 FilterMapper_RegisterPin,
1567 FilterMapper_RegisterPinType,
1568 FilterMapper_UnregisterFilter,
1569 FilterMapper_UnregisterFilterInstance,
1570 FilterMapper_UnregisterPin,
1571 FilterMapper_EnumMatchingFilters