winhelp: Window style has not been initialized.
[wine/multimedia.git] / dlls / quartz / filtermapper.c
blob8ee226e068d4d725396af96a28caee5a908154d9
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 CoTaskMemFree(v->pData);
156 v->current = 0;
157 v->capacity = 0;
160 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
162 FilterMapper2Impl * pFM2impl;
164 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
166 if (pUnkOuter)
167 return CLASS_E_NOAGGREGATION;
169 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
170 if (!pFM2impl)
171 return E_OUTOFMEMORY;
173 pFM2impl->lpVtbl = &fm2vtbl;
174 pFM2impl->lpVtblFilterMapper = &fmvtbl;
175 pFM2impl->refCount = 1;
177 *ppObj = pFM2impl;
179 TRACE("-- created at %p\n", pFM2impl);
181 return S_OK;
184 /*** IUnknown methods ***/
186 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
188 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
190 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
192 *ppv = NULL;
194 if (IsEqualIID(riid, &IID_IUnknown))
195 *ppv = iface;
196 else if (IsEqualIID(riid, &IID_IFilterMapper2))
197 *ppv = iface;
198 else if (IsEqualIID(riid, &IID_IFilterMapper))
199 *ppv = &This->lpVtblFilterMapper;
201 if (*ppv != NULL)
203 IUnknown_AddRef((IUnknown *)*ppv);
204 return S_OK;
207 FIXME("No interface for %s\n", debugstr_guid(riid));
208 return E_NOINTERFACE;
211 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
213 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
214 ULONG refCount = InterlockedIncrement(&This->refCount);
216 TRACE("(%p)->()\n", iface);
218 return refCount;
221 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
223 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
224 ULONG refCount = InterlockedDecrement(&This->refCount);
226 TRACE("(%p)->()\n", iface);
228 if (refCount == 0)
230 CoTaskMemFree(This);
231 return 0;
233 return refCount;
236 /*** IFilterMapper2 methods ***/
238 static HRESULT WINAPI FilterMapper2_CreateCategory(
239 IFilterMapper2 * iface,
240 REFCLSID clsidCategory,
241 DWORD dwCategoryMerit,
242 LPCWSTR szDescription)
244 LPWSTR wClsidAMCat = NULL;
245 LPWSTR wClsidCategory = NULL;
246 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
247 HKEY hKey = NULL;
248 LONG lRet;
249 HRESULT hr;
251 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
253 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
255 if (SUCCEEDED(hr))
257 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
260 if (SUCCEEDED(hr))
262 strcpyW(wszKeyName, wszClsidSlash);
263 strcatW(wszKeyName, wClsidAMCat);
264 strcatW(wszKeyName, wszSlashInstance);
265 strcatW(wszKeyName, wClsidCategory);
267 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
268 hr = HRESULT_FROM_WIN32(lRet);
271 if (SUCCEEDED(hr))
273 lRet = RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (const BYTE*)szDescription, (strlenW(szDescription) + 1) * sizeof(WCHAR));
274 hr = HRESULT_FROM_WIN32(lRet);
277 if (SUCCEEDED(hr))
279 lRet = RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, (strlenW(wClsidCategory) + 1) * sizeof(WCHAR));
280 hr = HRESULT_FROM_WIN32(lRet);
283 if (SUCCEEDED(hr))
285 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit));
286 hr = HRESULT_FROM_WIN32(lRet);
289 CloseHandle(hKey);
290 CoTaskMemFree(wClsidCategory);
291 CoTaskMemFree(wClsidAMCat);
293 return hr;
296 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
297 IFilterMapper2 * iface,
298 const CLSID *pclsidCategory,
299 const OLECHAR *szInstance,
300 REFCLSID Filter)
302 WCHAR wszKeyName[MAX_PATH];
303 LPWSTR wClsidCategory = NULL;
304 LPWSTR wFilter = NULL;
305 HRESULT hr;
307 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
309 if (!pclsidCategory)
310 pclsidCategory = &CLSID_LegacyAmFilterCategory;
312 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
314 if (SUCCEEDED(hr))
316 strcpyW(wszKeyName, wszClsidSlash);
317 strcatW(wszKeyName, wClsidCategory);
318 strcatW(wszKeyName, wszSlashInstance);
319 if (szInstance)
320 strcatW(wszKeyName, szInstance);
321 else
323 hr = StringFromCLSID(Filter, &wFilter);
324 if (SUCCEEDED(hr))
325 strcatW(wszKeyName, wFilter);
329 if (SUCCEEDED(hr))
331 LONG lRet = RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName);
332 hr = HRESULT_FROM_WIN32(lRet);
335 CoTaskMemFree(wClsidCategory);
336 CoTaskMemFree(wFilter);
338 return hr;
341 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
343 VARIANT var;
345 V_VT(&var) = VT_BSTR;
346 V_UNION(&var, bstrVal) = (BSTR)szName;
348 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
351 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
353 LPWSTR wszClsid = NULL;
354 VARIANT var;
355 HRESULT hr;
357 hr = StringFromCLSID(clsid, &wszClsid);
359 if (SUCCEEDED(hr))
361 V_VT(&var) = VT_BSTR;
362 V_UNION(&var, bstrVal) = wszClsid;
363 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
365 CoTaskMemFree(wszClsid);
366 return hr;
369 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
371 VARIANT var;
372 int size = sizeof(struct REG_RF);
373 unsigned int i;
374 struct Vector mainStore = {NULL, 0, 0};
375 struct Vector clsidStore = {NULL, 0, 0};
376 struct REG_RF rrf;
377 SAFEARRAY * psa;
378 SAFEARRAYBOUND saBound;
379 HRESULT hr = S_OK;
381 rrf.dwVersion = prf2->dwVersion;
382 rrf.dwMerit = prf2->dwMerit;
383 rrf.dwPins = prf2->u.s1.cPins2;
384 rrf.dwUnused = 0;
386 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
388 for (i = 0; i < prf2->u.s1.cPins2; i++)
390 size += sizeof(struct REG_RFP);
391 if (prf2->u.s1.rgPins2[i].clsPinCategory)
392 size += sizeof(DWORD);
393 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
394 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
397 for (i = 0; i < prf2->u.s1.cPins2; i++)
399 struct REG_RFP rrfp;
400 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
401 unsigned int j;
403 rrfp.signature[0] = '0';
404 rrfp.signature[1] = 'p';
405 rrfp.signature[2] = 'i';
406 rrfp.signature[3] = '3';
407 rrfp.signature[0] += i;
408 rrfp.dwFlags = rgPin2.dwFlags;
409 rrfp.dwInstances = rgPin2.cInstances;
410 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
411 rrfp.dwMediums = rgPin2.nMediums;
412 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
414 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
415 if (rrfp.bCategory)
417 DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
418 if (index == -1)
419 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
420 index += size;
422 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
425 for (j = 0; j < rgPin2.nMediaTypes; j++)
427 struct REG_TYPE rt;
428 rt.signature[0] = '0';
429 rt.signature[1] = 't';
430 rt.signature[2] = 'y';
431 rt.signature[3] = '3';
432 rt.signature[0] += j;
434 rt.dwUnused = 0;
435 rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
436 if (rt.dwOffsetMajor == -1)
437 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
438 rt.dwOffsetMajor += size;
439 rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
440 if (rt.dwOffsetMinor == -1)
441 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
442 rt.dwOffsetMinor += size;
444 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
447 for (j = 0; j < rgPin2.nMediums; j++)
449 DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
450 if (index == -1)
451 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
452 index += size;
454 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
458 saBound.lLbound = 0;
459 saBound.cElements = mainStore.current + clsidStore.current;
460 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
461 if (!psa)
463 ERR("Couldn't create SAFEARRAY\n");
464 hr = E_FAIL;
467 if (SUCCEEDED(hr))
469 LPBYTE pbSAData;
470 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
471 if (SUCCEEDED(hr))
473 memcpy(pbSAData, mainStore.pData, mainStore.current);
474 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
475 hr = SafeArrayUnaccessData(psa);
479 V_VT(&var) = VT_ARRAY | VT_UI1;
480 V_UNION(&var, parray) = psa;
482 if (SUCCEEDED(hr))
483 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
485 if (psa)
486 SafeArrayDestroy(psa);
488 delete_vector(&mainStore);
489 delete_vector(&clsidStore);
490 return hr;
493 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
495 VARIANT var;
496 HRESULT hr;
497 LPBYTE pData = NULL;
498 struct REG_RF * prrf;
499 LPBYTE pCurrent;
500 DWORD i;
501 REGFILTERPINS2 * rgPins2;
503 VariantInit(&var);
504 V_VT(&var) = VT_ARRAY | VT_UI1;
506 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
508 if (SUCCEEDED(hr))
509 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
511 if (SUCCEEDED(hr))
513 prrf = (struct REG_RF *)pData;
514 pCurrent = pData;
516 if (prrf->dwVersion != 2)
518 FIXME("Filter registry version %d not supported\n", prrf->dwVersion);
519 ZeroMemory(prf2, sizeof(*prf2));
520 hr = E_FAIL;
524 if (SUCCEEDED(hr))
526 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
527 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
529 prf2->dwVersion = prrf->dwVersion;
530 prf2->dwMerit = prrf->dwMerit;
531 prf2->u.s1.cPins2 = prrf->dwPins;
532 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
533 prf2->u.s1.rgPins2 = rgPins2;
534 pCurrent += sizeof(struct REG_RF);
536 for (i = 0; i < prrf->dwPins; i++)
538 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
539 REGPINTYPES * lpMediaType;
540 REGPINMEDIUM * lpMedium;
541 UINT j;
543 /* FIXME: check signature */
545 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp->signature, 4));
547 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
548 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
550 rgPins2[i].dwFlags = prrfp->dwFlags;
551 rgPins2[i].cInstances = prrfp->dwInstances;
552 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
553 rgPins2[i].nMediums = prrfp->dwMediums;
554 pCurrent += sizeof(struct REG_RFP);
555 if (prrfp->bCategory)
557 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
558 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
559 pCurrent += sizeof(DWORD);
560 rgPins2[i].clsPinCategory = clsCat;
562 else
563 rgPins2[i].clsPinCategory = NULL;
565 if (rgPins2[i].nMediaTypes > 0)
566 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
567 else
568 lpMediaType = NULL;
570 rgPins2[i].lpMediaType = lpMediaType;
572 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
574 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
575 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
576 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
578 /* FIXME: check signature */
579 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt->signature, 4));
581 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
582 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
584 lpMediaType[j].clsMajorType = clsMajor;
585 lpMediaType[j].clsMinorType = clsMinor;
587 pCurrent += sizeof(*prt);
590 if (rgPins2[i].nMediums > 0)
591 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
592 else
593 lpMedium = NULL;
595 rgPins2[i].lpMedium = lpMedium;
597 for (j = 0; j < rgPins2[i].nMediums; j++)
599 DWORD dwOffset = *(DWORD *)pCurrent;
601 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
603 pCurrent += sizeof(dwOffset);
609 if (pData)
610 SafeArrayUnaccessData(V_UNION(&var, parray));
612 VariantClear(&var);
614 return hr;
617 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
619 UINT i;
620 for (i = 0; i < prf2->u.s1.cPins2; i++)
622 UINT j;
623 if (prf2->u.s1.rgPins2[i].clsPinCategory)
624 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
626 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
628 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
629 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
631 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
635 static HRESULT WINAPI FilterMapper2_RegisterFilter(
636 IFilterMapper2 * iface,
637 REFCLSID clsidFilter,
638 LPCWSTR szName,
639 IMoniker **ppMoniker,
640 const CLSID *pclsidCategory,
641 const OLECHAR *szInstance,
642 const REGFILTER2 *prf2)
644 IParseDisplayName * pParser = NULL;
645 IBindCtx * pBindCtx = NULL;
646 IMoniker * pMoniker = NULL;
647 IPropertyBag * pPropBag = NULL;
648 HRESULT hr;
649 LPWSTR pwszParseName = NULL;
650 LPWSTR pCurrent;
651 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
652 int nameLen;
653 ULONG ulEaten;
654 LPWSTR szClsidTemp = NULL;
655 REGFILTER2 regfilter2;
656 REGFILTERPINS2* pregfp2 = NULL;
658 TRACE("(%s, %s, %p, %s, %s, %p)\n",
659 debugstr_guid(clsidFilter),
660 debugstr_w(szName),
661 ppMoniker,
662 debugstr_guid(pclsidCategory),
663 debugstr_w(szInstance),
664 prf2);
666 if (prf2->dwVersion == 2)
668 regfilter2 = *prf2;
670 else if (prf2->dwVersion == 1)
672 ULONG i;
673 DWORD flags;
674 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
675 regfilter2.dwVersion = 2;
676 regfilter2.dwMerit = prf2->dwMerit;
677 regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
678 pregfp2 = (REGFILTERPINS2*) CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
679 regfilter2.u.s1.rgPins2 = pregfp2;
680 for (i = 0; i < prf2->u.s.cPins; i++)
682 flags = 0;
683 if (prf2->u.s.rgPins[i].bRendered)
684 flags |= REG_PINFLAG_B_RENDERER;
685 if (prf2->u.s.rgPins[i].bOutput)
686 flags |= REG_PINFLAG_B_OUTPUT;
687 if (prf2->u.s.rgPins[i].bZero)
688 flags |= REG_PINFLAG_B_ZERO;
689 if (prf2->u.s.rgPins[i].bMany)
690 flags |= REG_PINFLAG_B_MANY;
691 pregfp2[i].dwFlags = flags;
692 pregfp2[i].cInstances = 1;
693 pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
694 pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
695 pregfp2[i].nMediums = 0;
696 pregfp2[i].lpMedium = NULL;
697 pregfp2[i].clsPinCategory = NULL;
700 else
702 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
703 return E_NOTIMPL;
706 if (ppMoniker)
707 *ppMoniker = NULL;
709 if (!pclsidCategory)
710 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
711 * In fact this is the CLSID_LegacyAmFilterCategory one */
712 pclsidCategory = &CLSID_LegacyAmFilterCategory;
714 /* sizeof... will include the null terminator and
715 * the + 1 is for the separator ('\\'). The -1 is
716 * because CHARS_IN_GUID includes the null terminator
718 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
720 if (szInstance)
721 nameLen += strlenW(szInstance);
722 else
723 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
725 pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
726 if (!pwszParseName)
727 return E_OUTOFMEMORY;
729 strcpyW(pwszParseName, wszDevice);
730 pCurrent += strlenW(wszDevice);
732 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
734 if (SUCCEEDED(hr))
736 memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
737 pCurrent += CHARS_IN_GUID - 1;
738 pCurrent[0] = '\\';
740 if (szInstance)
741 strcpyW(pCurrent+1, szInstance);
742 else
744 CoTaskMemFree(szClsidTemp);
745 szClsidTemp = NULL;
747 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
748 if (SUCCEEDED(hr))
749 strcpyW(pCurrent+1, szClsidTemp);
753 if (SUCCEEDED(hr))
754 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
756 if (SUCCEEDED(hr))
757 hr = CreateBindCtx(0, &pBindCtx);
759 if (SUCCEEDED(hr))
760 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
762 if (pBindCtx)
763 IBindCtx_Release(pBindCtx);
764 if (pParser)
765 IParseDisplayName_Release(pParser);
767 if (SUCCEEDED(hr))
768 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
770 if (SUCCEEDED(hr))
771 hr = FM2_WriteFriendlyName(pPropBag, szName);
773 if (SUCCEEDED(hr))
774 hr = FM2_WriteClsid(pPropBag, clsidFilter);
776 if (SUCCEEDED(hr))
777 hr = FM2_WriteFilterData(pPropBag, &regfilter2);
779 if (pPropBag)
780 IPropertyBag_Release(pPropBag);
781 CoTaskMemFree(szClsidTemp);
783 if (SUCCEEDED(hr) && ppMoniker)
784 *ppMoniker = pMoniker;
785 else if (pMoniker)
786 IMoniker_Release(pMoniker);
788 CoTaskMemFree(pregfp2);
790 TRACE("-- returning %x\n", hr);
792 return hr;
795 /* internal helper function */
796 static BOOL MatchTypes(
797 BOOL bExactMatch,
798 DWORD nPinTypes,
799 const REGPINTYPES * pPinTypes,
800 DWORD nMatchTypes,
801 const GUID * pMatchTypes)
803 BOOL bMatch = FALSE;
804 DWORD j;
806 if ((nMatchTypes == 0) && (nPinTypes > 0))
807 bMatch = TRUE;
809 for (j = 0; j < nPinTypes; j++)
811 DWORD i;
812 for (i = 0; i < nMatchTypes*2; i+=2)
814 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
815 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
817 bMatch = TRUE;
818 break;
822 return bMatch;
825 /* internal helper function for qsort of MONIKER_MERIT array */
826 static int mm_compare(const void * left, const void * right)
828 const struct MONIKER_MERIT * mmLeft = (const struct MONIKER_MERIT *)left;
829 const struct MONIKER_MERIT * mmRight = (const struct MONIKER_MERIT *)right;
831 if (mmLeft->dwMerit == mmRight->dwMerit)
832 return 0;
833 if (mmLeft->dwMerit > mmRight->dwMerit)
834 return -1;
835 return 1;
838 /* NOTES:
839 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
840 * (GUID_NULL's in input to function automatically treated as wild cards)
841 * Input/Output needed means match only on criteria if TRUE (with zero input types
842 * meaning match any input/output pin as long as one exists), otherwise match any
843 * filter that meets the rest of the requirements.
845 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
846 IFilterMapper2 * iface,
847 IEnumMoniker **ppEnum,
848 DWORD dwFlags,
849 BOOL bExactMatch,
850 DWORD dwMerit,
851 BOOL bInputNeeded,
852 DWORD cInputTypes,
853 const GUID *pInputTypes,
854 const REGPINMEDIUM *pMedIn,
855 const CLSID *pPinCategoryIn,
856 BOOL bRender,
857 BOOL bOutputNeeded,
858 DWORD cOutputTypes,
859 const GUID *pOutputTypes,
860 const REGPINMEDIUM *pMedOut,
861 const CLSID *pPinCategoryOut)
863 ICreateDevEnum * pCreateDevEnum;
864 IMoniker * pMonikerCat;
865 IEnumMoniker * pEnumCat;
866 HRESULT hr;
867 struct Vector monikers = {NULL, 0, 0};
869 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
870 ppEnum,
871 dwFlags,
872 bExactMatch ? "true" : "false",
873 dwMerit,
874 bInputNeeded ? "true" : "false",
875 cInputTypes,
876 pInputTypes,
877 pMedIn,
878 pPinCategoryIn,
879 bRender ? "true" : "false",
880 bOutputNeeded ? "true" : "false",
881 pOutputTypes,
882 pMedOut,
883 pPinCategoryOut);
885 if (dwFlags != 0)
887 FIXME("dwFlags = %x not implemented\n", dwFlags);
890 *ppEnum = NULL;
892 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
894 if (SUCCEEDED(hr))
895 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
897 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
899 IPropertyBag * pPropBagCat = NULL;
900 VARIANT var;
901 HRESULT hrSub; /* this is so that one buggy filter
902 doesn't make the whole lot fail */
904 VariantInit(&var);
906 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
908 if (SUCCEEDED(hrSub))
909 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
911 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
913 CLSID clsidCat;
914 IEnumMoniker * pEnum;
915 IMoniker * pMoniker;
917 VariantClear(&var);
919 if (TRACE_ON(quartz))
921 VARIANT temp;
922 V_VT(&temp) = VT_EMPTY;
923 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
924 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
925 VariantClear(&temp);
928 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
930 if (SUCCEEDED(hrSub))
931 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
933 if (SUCCEEDED(hrSub))
934 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
936 if (hrSub == S_OK)
938 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
940 IPropertyBag * pPropBag = NULL;
941 REGFILTER2 rf2;
942 DWORD i;
943 BOOL bInputMatch = !bInputNeeded;
944 BOOL bOutputMatch = !bOutputNeeded;
946 ZeroMemory(&rf2, sizeof(rf2));
948 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
950 if (TRACE_ON(quartz))
952 VARIANT temp;
953 V_VT(&temp) = VT_EMPTY;
954 IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
955 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
956 VariantClear(&temp);
959 if (SUCCEEDED(hrSub))
960 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
962 /* Logic used for bInputMatch expression:
963 * There exists some pin such that bInputNeeded implies (pin is an input and
964 * (bRender implies pin has render flag) and major/minor types members of
965 * pInputTypes )
966 * bOutputMatch is similar, but without the "bRender implies ..." part
967 * and substituting variables names containing input for output
970 /* determine whether filter meets requirements */
971 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
973 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
975 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
977 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
978 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
979 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
980 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
981 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
984 if (bInputMatch && bOutputMatch)
986 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
987 IMoniker_AddRef(pMoniker);
988 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
992 FM2_DeleteRegFilter(&rf2);
993 if (pPropBag)
994 IPropertyBag_Release(pPropBag);
995 IMoniker_Release(pMoniker);
997 IEnumMoniker_Release(pEnum);
1001 VariantClear(&var);
1002 if (pPropBagCat)
1003 IPropertyBag_Release(pPropBagCat);
1004 IMoniker_Release(pMonikerCat);
1007 if (SUCCEEDED(hr))
1009 IMoniker ** ppMoniker;
1010 unsigned int i;
1011 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1013 /* sort the monikers in descending merit order */
1014 qsort(monikers.pData, nMonikerCount,
1015 sizeof(struct MONIKER_MERIT),
1016 mm_compare);
1018 /* construct an IEnumMoniker interface */
1019 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1020 for (i = 0; i < nMonikerCount; i++)
1022 /* no need to AddRef here as already AddRef'd above */
1023 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1025 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1026 CoTaskMemFree(ppMoniker);
1029 delete_vector(&monikers);
1030 IEnumMoniker_Release(pEnumCat);
1031 ICreateDevEnum_Release(pCreateDevEnum);
1033 return hr;
1036 static const IFilterMapper2Vtbl fm2vtbl =
1039 FilterMapper2_QueryInterface,
1040 FilterMapper2_AddRef,
1041 FilterMapper2_Release,
1043 FilterMapper2_CreateCategory,
1044 FilterMapper2_UnregisterFilter,
1045 FilterMapper2_RegisterFilter,
1046 FilterMapper2_EnumMatchingFilters
1049 /*** IUnknown methods ***/
1051 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1053 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1055 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1057 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1060 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1062 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1064 return FilterMapper2_AddRef((IFilterMapper2*)This);
1067 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1069 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1071 return FilterMapper2_Release((IFilterMapper2*)This);
1074 /*** IFilterMapper methods ***/
1076 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1077 IFilterMapper * iface,
1078 IEnumRegFilters **ppEnum,
1079 DWORD dwMerit,
1080 BOOL bInputNeeded,
1081 CLSID clsInMaj,
1082 CLSID clsInSub,
1083 BOOL bRender,
1084 BOOL bOutputNeeded,
1085 CLSID clsOutMaj,
1086 CLSID clsOutSub)
1088 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1089 GUID InputType[2];
1090 GUID OutputType[2];
1091 IEnumMoniker* ppEnumMoniker;
1092 IMoniker* IMon;
1093 ULONG nb;
1094 ULONG idx = 0, nb_mon = 0;
1095 REGFILTER* regfilters;
1096 HRESULT hr;
1098 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1099 iface,This,
1100 ppEnum,
1101 dwMerit,
1102 bInputNeeded ? "true" : "false",
1103 debugstr_guid(&clsInMaj),
1104 debugstr_guid(&clsInSub),
1105 bRender ? "true" : "false",
1106 bOutputNeeded ? "true" : "false",
1107 debugstr_guid(&clsOutMaj),
1108 debugstr_guid(&clsOutSub));
1110 InputType[0] = clsInMaj;
1111 InputType[1] = clsInSub;
1112 OutputType[0] = clsOutMaj;
1113 OutputType[1] = clsOutSub;
1115 hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1116 &ppEnumMoniker,
1118 TRUE,
1119 dwMerit,
1120 bInputNeeded,
1122 InputType,
1123 NULL,
1124 &GUID_NULL,
1125 bRender,
1126 bOutputNeeded,
1128 OutputType,
1129 NULL,
1130 &GUID_NULL);
1132 if (!SUCCEEDED(hr))
1133 return hr;
1135 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1137 IMoniker_Release(IMon);
1138 nb_mon++;
1141 *ppEnum = NULL;
1142 if (!nb_mon)
1144 IEnumMoniker_Release(ppEnumMoniker);
1145 return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1148 regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1149 if (!regfilters)
1151 IEnumMoniker_Release(ppEnumMoniker);
1152 return E_OUTOFMEMORY;
1155 IEnumMoniker_Reset(ppEnumMoniker);
1156 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1158 IPropertyBag * pPropBagCat = NULL;
1159 VARIANT var;
1160 HRESULT hrSub;
1161 GUID clsid;
1162 int len;
1164 VariantInit(&var);
1165 V_VT(&var) = VT_BSTR;
1167 hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1169 if (SUCCEEDED(hrSub))
1170 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1172 if (SUCCEEDED(hrSub))
1173 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1175 if (SUCCEEDED(hrSub))
1176 hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1178 if (SUCCEEDED(hrSub))
1180 len = (strlenW((WCHAR*)&V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1181 if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1182 hr = E_OUTOFMEMORY;
1185 if (SUCCEEDED(hrSub))
1187 memcpy(regfilters[idx].Name, &V_UNION(&var, bstrVal), len);
1188 regfilters[idx].Clsid = clsid;
1189 idx++;
1192 if (pPropBagCat)
1193 IPropertyBag_Release(pPropBagCat);
1194 IMoniker_Release(IMon);
1197 /* In case of release all resources */
1198 if (!SUCCEEDED(hr))
1200 for (idx = 0; idx < nb_mon; idx++)
1201 CoTaskMemFree(regfilters[idx].Name);
1202 CoTaskMemFree(regfilters);
1203 IEnumMoniker_Release(ppEnumMoniker);
1204 return hr;
1207 hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1208 CoTaskMemFree(regfilters);
1209 IEnumMoniker_Release(ppEnumMoniker);
1211 return hr;
1215 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1217 HRESULT hr;
1218 LPWSTR wszClsid = NULL;
1219 HKEY hKey;
1220 LONG lRet;
1221 WCHAR wszKeyName[strlenW(wszFilterSlash) + (CHARS_IN_GUID-1) + 1];
1223 TRACE("(%p)->(%s, %s, %x)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1225 hr = StringFromCLSID(&clsid, &wszClsid);
1227 if (SUCCEEDED(hr))
1229 strcpyW(wszKeyName, wszFilterSlash);
1230 strcatW(wszKeyName, wszClsid);
1232 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1233 hr = HRESULT_FROM_WIN32(lRet);
1236 if (SUCCEEDED(hr))
1238 lRet = RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, strlenW(szName) + 1);
1239 hr = HRESULT_FROM_WIN32(lRet);
1240 CloseHandle(hKey);
1243 if (SUCCEEDED(hr))
1245 strcpyW(wszKeyName, wszClsidSlash);
1246 strcatW(wszKeyName, wszClsid);
1248 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1249 hr = HRESULT_FROM_WIN32(lRet);
1252 if (SUCCEEDED(hr))
1254 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit));
1255 hr = HRESULT_FROM_WIN32(lRet);
1256 CloseHandle(hKey);
1259 return hr;
1262 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1264 TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1266 /* Not implemented in Windows (tested on Win2k) */
1268 return E_NOTIMPL;
1271 static HRESULT WINAPI FilterMapper_RegisterPin(
1272 IFilterMapper * iface,
1273 CLSID Filter,
1274 LPCWSTR szName,
1275 BOOL bRendered,
1276 BOOL bOutput,
1277 BOOL bZero,
1278 BOOL bMany,
1279 CLSID ConnectsToFilter,
1280 LPCWSTR ConnectsToPin)
1282 HRESULT hr;
1283 LONG lRet;
1284 LPWSTR wszClsid = NULL;
1285 HKEY hKey = NULL;
1286 HKEY hPinsKey = NULL;
1287 WCHAR * wszPinsKeyName;
1288 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1290 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1291 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1293 hr = StringFromCLSID(&Filter, &wszClsid);
1295 if (SUCCEEDED(hr))
1297 strcpyW(wszKeyName, wszClsidSlash);
1298 strcatW(wszKeyName, wszClsid);
1300 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1301 hr = HRESULT_FROM_WIN32(lRet);
1304 if (SUCCEEDED(hr))
1306 wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1307 if (!wszPinsKeyName)
1308 hr = E_OUTOFMEMORY;
1311 if (SUCCEEDED(hr))
1313 strcpyW(wszPinsKeyName, wszPins);
1314 strcatW(wszPinsKeyName, wszSlash);
1315 strcatW(wszPinsKeyName, szName);
1317 lRet = RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL);
1318 hr = HRESULT_FROM_WIN32(lRet);
1319 CoTaskMemFree(wszPinsKeyName);
1322 if (SUCCEEDED(hr))
1324 lRet = RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany));
1325 hr = HRESULT_FROM_WIN32(lRet);
1328 if (SUCCEEDED(hr))
1330 lRet = RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero));
1331 hr = HRESULT_FROM_WIN32(lRet);
1334 if (SUCCEEDED(hr))
1336 lRet = RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput));
1337 hr = HRESULT_FROM_WIN32(lRet);
1340 if (SUCCEEDED(hr))
1342 lRet = RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered));
1343 hr = HRESULT_FROM_WIN32(lRet);
1346 if (SUCCEEDED(hr))
1348 lRet = RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL);
1349 hr = HRESULT_FROM_WIN32(lRet);
1352 CoTaskMemFree(wszClsid);
1353 if (hKey)
1354 CloseHandle(hKey);
1355 if (hPinsKey)
1356 CloseHandle(hPinsKey);
1358 return hr;
1362 static HRESULT WINAPI FilterMapper_RegisterPinType(
1363 IFilterMapper * iface,
1364 CLSID clsFilter,
1365 LPCWSTR szName,
1366 CLSID clsMajorType,
1367 CLSID clsSubType)
1369 HRESULT hr;
1370 LONG lRet;
1371 LPWSTR wszClsid = NULL;
1372 LPWSTR wszClsidMajorType = NULL;
1373 LPWSTR wszClsidSubType = NULL;
1374 HKEY hKey = NULL;
1375 WCHAR * wszTypesKey;
1376 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1378 TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1379 debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1381 hr = StringFromCLSID(&clsFilter, &wszClsid);
1383 if (SUCCEEDED(hr))
1385 hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1388 if (SUCCEEDED(hr))
1390 hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1393 if (SUCCEEDED(hr))
1395 wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1396 strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1397 if (!wszTypesKey)
1398 hr = E_OUTOFMEMORY;
1401 if (SUCCEEDED(hr))
1403 strcpyW(wszTypesKey, wszClsidSlash);
1404 strcatW(wszTypesKey, wszClsid);
1405 strcatW(wszTypesKey, wszSlash);
1406 strcatW(wszTypesKey, wszPins);
1407 strcatW(wszTypesKey, wszSlash);
1408 strcatW(wszTypesKey, szName);
1409 strcatW(wszTypesKey, wszSlash);
1410 strcatW(wszTypesKey, wszTypes);
1412 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey);
1413 hr = HRESULT_FROM_WIN32(lRet);
1414 CoTaskMemFree(wszTypesKey);
1417 if (SUCCEEDED(hr))
1419 strcpyW(wszKeyName, wszClsidMajorType);
1420 strcatW(wszKeyName, wszSlash);
1421 strcatW(wszKeyName, wszClsidSubType);
1423 lRet = RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL);
1424 hr = HRESULT_FROM_WIN32(lRet);
1425 CloseHandle(hKey);
1428 CoTaskMemFree(wszClsid);
1429 CoTaskMemFree(wszClsidMajorType);
1430 CoTaskMemFree(wszClsidSubType);
1432 return hr;
1435 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1437 HRESULT hr;
1438 LONG lRet;
1439 LPWSTR wszClsid = NULL;
1440 HKEY hKey;
1441 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1443 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1445 hr = StringFromCLSID(&Filter, &wszClsid);
1447 if (SUCCEEDED(hr))
1449 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey);
1450 hr = HRESULT_FROM_WIN32(lRet);
1453 if (SUCCEEDED(hr))
1455 lRet = RegDeleteKeyW(hKey, wszClsid);
1456 hr = HRESULT_FROM_WIN32(lRet);
1457 CloseHandle(hKey);
1460 if (SUCCEEDED(hr))
1462 strcpyW(wszKeyName, wszClsidSlash);
1463 strcatW(wszKeyName, wszClsid);
1465 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1466 hr = HRESULT_FROM_WIN32(lRet);
1469 if (SUCCEEDED(hr))
1471 lRet = RegDeleteKeyW(hKey, wszMeritName);
1472 hr = HRESULT_FROM_WIN32(lRet);
1473 CloseHandle(hKey);
1476 CoTaskMemFree(wszClsid);
1478 return hr;
1481 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1483 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1485 /* Not implemented in Windows (tested on Win2k) */
1487 return E_NOTIMPL;
1490 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1492 HRESULT hr;
1493 LONG lRet;
1494 LPWSTR wszClsid = NULL;
1495 HKEY hKey = NULL;
1496 WCHAR * wszPinNameKey;
1497 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1499 TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1501 if (!Name)
1502 return E_INVALIDARG;
1504 hr = StringFromCLSID(&Filter, &wszClsid);
1506 if (SUCCEEDED(hr))
1508 strcpyW(wszKeyName, wszClsidSlash);
1509 strcatW(wszKeyName, wszClsid);
1511 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1512 hr = HRESULT_FROM_WIN32(lRet);
1515 if (SUCCEEDED(hr))
1517 wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1518 if (!wszPinNameKey)
1519 hr = E_OUTOFMEMORY;
1522 if (SUCCEEDED(hr))
1524 strcpyW(wszPinNameKey, wszPins);
1525 strcatW(wszPinNameKey, wszSlash);
1526 strcatW(wszPinNameKey, Name);
1528 lRet = RegDeleteKeyW(hKey, wszPinNameKey);
1529 hr = HRESULT_FROM_WIN32(lRet);
1530 CoTaskMemFree(wszPinNameKey);
1533 CoTaskMemFree(wszClsid);
1534 if (hKey)
1535 CloseHandle(hKey);
1537 return hr;
1540 static const IFilterMapperVtbl fmvtbl =
1543 FilterMapper_QueryInterface,
1544 FilterMapper_AddRef,
1545 FilterMapper_Release,
1547 FilterMapper_RegisterFilter,
1548 FilterMapper_RegisterFilterInstance,
1549 FilterMapper_RegisterPin,
1550 FilterMapper_RegisterPinType,
1551 FilterMapper_UnregisterFilter,
1552 FilterMapper_UnregisterFilterInstance,
1553 FilterMapper_UnregisterPin,
1554 FilterMapper_EnumMatchingFilters