pdh: Implement and test PdhSetCounterScaleFactor and PdhGetFormattedCounterValue.
[wine.git] / dlls / quartz / regsvr.c
blob20bc5c4e7316fa13dfaaab4afdcefd9032586973
1 /*
2 * self-registerable dll functions for quartz.dll
4 * Copyright (C) 2003 John K. Hohm
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
24 #include <stdarg.h>
25 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "winerror.h"
33 #include "ole2.h"
34 #include "uuids.h"
35 #include "strmif.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
42 * Near the bottom of this file are the exported DllRegisterServer and
43 * DllUnregisterServer, which make all this worthwhile.
46 /***********************************************************************
47 * interface for self-registering
49 struct regsvr_interface
51 IID const *iid; /* NULL for end of list */
52 LPCSTR name; /* can be NULL to omit */
53 IID const *base_iid; /* can be NULL to omit */
54 int num_methods; /* can be <0 to omit */
55 CLSID const *ps_clsid; /* can be NULL to omit */
56 CLSID const *ps_clsid32; /* can be NULL to omit */
59 static HRESULT register_interfaces(struct regsvr_interface const *list);
60 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
62 struct regsvr_coclass
64 CLSID const *clsid; /* NULL for end of list */
65 LPCSTR name; /* can be NULL to omit */
66 LPCSTR ips; /* can be NULL to omit */
67 LPCSTR ips32; /* can be NULL to omit */
68 LPCSTR ips32_tmodel; /* can be NULL to omit */
69 LPCSTR progid; /* can be NULL to omit */
70 LPCSTR viprogid; /* can be NULL to omit */
71 LPCSTR progid_extra; /* can be NULL to omit */
74 static HRESULT register_coclasses(struct regsvr_coclass const *list);
75 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
77 struct regsvr_mediatype_parsing
79 CLSID const *majortype; /* NULL for end of list */
80 CLSID const *subtype;
81 LPCSTR line[11]; /* NULL for end of list */
84 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
85 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
87 struct regsvr_mediatype_extension
89 CLSID const *majortype; /* NULL for end of list */
90 CLSID const *subtype;
91 LPCSTR extension;
94 struct mediatype
96 CLSID const *majortype; /* NULL for end of list */
97 CLSID const *subtype;
98 DWORD fourcc;
101 struct pin
103 DWORD flags; /* 0xFFFFFFFF for end of list */
104 struct mediatype mediatypes[11];
107 struct regsvr_filter
109 CLSID const *clsid; /* NULL for end of list */
110 CLSID const *category;
111 WCHAR name[50];
112 DWORD merit;
113 struct pin pins[11];
116 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list);
117 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list);
119 static HRESULT register_filters(struct regsvr_filter const *list);
120 static HRESULT unregister_filters(struct regsvr_filter const *list);
122 /***********************************************************************
123 * static string constants
125 static WCHAR const interface_keyname[10] = {
126 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
127 static WCHAR const base_ifa_keyname[14] = {
128 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
129 'e', 0 };
130 static WCHAR const num_methods_keyname[11] = {
131 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
132 static WCHAR const ps_clsid_keyname[15] = {
133 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
134 'i', 'd', 0 };
135 static WCHAR const ps_clsid32_keyname[17] = {
136 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
137 'i', 'd', '3', '2', 0 };
138 static WCHAR const clsid_keyname[6] = {
139 'C', 'L', 'S', 'I', 'D', 0 };
140 static WCHAR const curver_keyname[7] = {
141 'C', 'u', 'r', 'V', 'e', 'r', 0 };
142 static WCHAR const ips_keyname[13] = {
143 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
144 0 };
145 static WCHAR const ips32_keyname[15] = {
146 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
147 '3', '2', 0 };
148 static WCHAR const progid_keyname[7] = {
149 'P', 'r', 'o', 'g', 'I', 'D', 0 };
150 static WCHAR const viprogid_keyname[25] = {
151 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
152 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
153 0 };
154 static char const tmodel_valuename[] = "ThreadingModel";
155 static WCHAR const mediatype_name[11] = {
156 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
157 static WCHAR const subtype_valuename[8] = {
158 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
159 static WCHAR const sourcefilter_valuename[14] = {
160 'S', 'o', 'u', 'r', 'c', 'e', ' ', 'F', 'i', 'l', 't', 'e', 'r', 0 };
161 static WCHAR const extensions_keyname[11] = {
162 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', 0 };
164 /***********************************************************************
165 * static helper functions
167 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
168 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
169 WCHAR const *value);
170 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
171 char const *value);
172 static LONG register_progid(WCHAR const *clsid,
173 char const *progid, char const *curver_progid,
174 char const *name, char const *extra);
175 static LONG recursive_delete_key(HKEY key);
176 static LONG recursive_delete_keyA(HKEY base, char const *name);
177 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name);
179 /***********************************************************************
180 * register_interfaces
182 static HRESULT register_interfaces(struct regsvr_interface const *list)
184 LONG res = ERROR_SUCCESS;
185 HKEY interface_key;
187 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
188 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
189 if (res != ERROR_SUCCESS) goto error_return;
191 for (; res == ERROR_SUCCESS && list->iid; ++list) {
192 WCHAR buf[39];
193 HKEY iid_key;
195 StringFromGUID2(list->iid, buf, 39);
196 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
197 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
198 if (res != ERROR_SUCCESS) goto error_close_interface_key;
200 if (list->name) {
201 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
202 (CONST BYTE*)(list->name),
203 strlen(list->name) + 1);
204 if (res != ERROR_SUCCESS) goto error_close_iid_key;
207 if (list->base_iid) {
208 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
209 if (res != ERROR_SUCCESS) goto error_close_iid_key;
212 if (0 <= list->num_methods) {
213 static WCHAR const fmt[3] = { '%', 'd', 0 };
214 HKEY key;
216 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
217 KEY_READ | KEY_WRITE, NULL, &key, NULL);
218 if (res != ERROR_SUCCESS) goto error_close_iid_key;
220 wsprintfW(buf, fmt, list->num_methods);
221 res = RegSetValueExW(key, NULL, 0, REG_SZ,
222 (CONST BYTE*)buf,
223 (lstrlenW(buf) + 1) * sizeof(WCHAR));
224 RegCloseKey(key);
226 if (res != ERROR_SUCCESS) goto error_close_iid_key;
229 if (list->ps_clsid) {
230 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
231 if (res != ERROR_SUCCESS) goto error_close_iid_key;
234 if (list->ps_clsid32) {
235 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
236 if (res != ERROR_SUCCESS) goto error_close_iid_key;
239 error_close_iid_key:
240 RegCloseKey(iid_key);
243 error_close_interface_key:
244 RegCloseKey(interface_key);
245 error_return:
246 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
249 /***********************************************************************
250 * unregister_interfaces
252 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
254 LONG res = ERROR_SUCCESS;
255 HKEY interface_key;
257 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
258 KEY_READ | KEY_WRITE, &interface_key);
259 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
260 if (res != ERROR_SUCCESS) goto error_return;
262 for (; res == ERROR_SUCCESS && list->iid; ++list) {
263 WCHAR buf[39];
265 StringFromGUID2(list->iid, buf, 39);
266 res = recursive_delete_keyW(interface_key, buf);
269 RegCloseKey(interface_key);
270 error_return:
271 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
274 /***********************************************************************
275 * register_coclasses
277 static HRESULT register_coclasses(struct regsvr_coclass const *list)
279 LONG res = ERROR_SUCCESS;
280 HKEY coclass_key;
282 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
283 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
284 if (res != ERROR_SUCCESS) goto error_return;
286 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
287 WCHAR buf[39];
288 HKEY clsid_key;
290 StringFromGUID2(list->clsid, buf, 39);
291 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
292 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
293 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
295 if (list->name) {
296 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
297 (CONST BYTE*)(list->name),
298 strlen(list->name) + 1);
299 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
302 if (list->ips) {
303 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
304 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
307 if (list->ips32) {
308 HKEY ips32_key;
310 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
311 KEY_READ | KEY_WRITE, NULL,
312 &ips32_key, NULL);
313 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
315 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
316 (CONST BYTE*)list->ips32,
317 lstrlenA(list->ips32) + 1);
318 if (res == ERROR_SUCCESS && list->ips32_tmodel)
319 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
320 (CONST BYTE*)list->ips32_tmodel,
321 strlen(list->ips32_tmodel) + 1);
322 RegCloseKey(ips32_key);
323 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
326 if (list->progid) {
327 res = register_key_defvalueA(clsid_key, progid_keyname,
328 list->progid);
329 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
331 res = register_progid(buf, list->progid, NULL,
332 list->name, list->progid_extra);
333 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
336 if (list->viprogid) {
337 res = register_key_defvalueA(clsid_key, viprogid_keyname,
338 list->viprogid);
339 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
341 res = register_progid(buf, list->viprogid, list->progid,
342 list->name, list->progid_extra);
343 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
346 error_close_clsid_key:
347 RegCloseKey(clsid_key);
350 error_close_coclass_key:
351 RegCloseKey(coclass_key);
352 error_return:
353 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
356 /***********************************************************************
357 * unregister_coclasses
359 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
361 LONG res = ERROR_SUCCESS;
362 HKEY coclass_key;
364 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
365 KEY_READ | KEY_WRITE, &coclass_key);
366 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
367 if (res != ERROR_SUCCESS) goto error_return;
369 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
370 WCHAR buf[39];
372 StringFromGUID2(list->clsid, buf, 39);
373 res = recursive_delete_keyW(coclass_key, buf);
374 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
376 if (list->progid) {
377 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->progid);
378 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
381 if (list->viprogid) {
382 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->viprogid);
383 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
387 error_close_coclass_key:
388 RegCloseKey(coclass_key);
389 error_return:
390 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
393 /***********************************************************************
394 * register_mediatypes_parsing
396 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
398 LONG res = ERROR_SUCCESS;
399 HKEY mediatype_key;
400 WCHAR buf[39];
401 int i;
403 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
404 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
405 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
407 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
408 HKEY majortype_key = NULL;
409 HKEY subtype_key = NULL;
411 StringFromGUID2(list->majortype, buf, 39);
412 res = RegCreateKeyExW(mediatype_key, buf, 0, NULL, 0,
413 KEY_READ | KEY_WRITE, NULL, &majortype_key, NULL);
414 if (res != ERROR_SUCCESS) goto error_close_keys;
416 StringFromGUID2(list->subtype, buf, 39);
417 res = RegCreateKeyExW(majortype_key, buf, 0, NULL, 0,
418 KEY_READ | KEY_WRITE, NULL, &subtype_key, NULL);
419 if (res != ERROR_SUCCESS) goto error_close_keys;
421 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
422 res = RegSetValueExW(subtype_key, sourcefilter_valuename, 0, REG_SZ, (CONST BYTE*)buf,
423 (lstrlenW(buf) + 1) * sizeof(WCHAR));
424 if (res != ERROR_SUCCESS) goto error_close_keys;
426 for(i = 0; list->line[i]; i++) {
427 char buffer[3];
428 wsprintfA(buffer, "%d", i);
429 res = RegSetValueExA(subtype_key, buffer, 0, REG_SZ, (CONST BYTE*)list->line[i],
430 lstrlenA(list->line[i]));
431 if (res != ERROR_SUCCESS) goto error_close_keys;
434 error_close_keys:
435 if (majortype_key)
436 RegCloseKey(majortype_key);
437 if (subtype_key)
438 RegCloseKey(subtype_key);
441 RegCloseKey(mediatype_key);
443 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
446 /***********************************************************************
447 * register_mediatypes_extension
449 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list)
451 LONG res = ERROR_SUCCESS;
452 HKEY mediatype_key;
453 HKEY extensions_root_key = NULL;
454 WCHAR buf[39];
456 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
457 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
458 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
460 res = RegCreateKeyExW(mediatype_key, extensions_keyname, 0, NULL, 0,
461 KEY_READ | KEY_WRITE, NULL, &extensions_root_key, NULL);
462 if (res != ERROR_SUCCESS) goto error_return;
464 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
465 HKEY extension_key;
467 res = RegCreateKeyExA(extensions_root_key, list->extension, 0, NULL, 0,
468 KEY_READ | KEY_WRITE, NULL, &extension_key, NULL);
469 if (res != ERROR_SUCCESS) break;
471 StringFromGUID2(list->majortype, buf, 39);
472 res = RegSetValueExW(extension_key, mediatype_name, 0, REG_SZ, (CONST BYTE*)buf,
473 (lstrlenW(buf) + 1) * sizeof(WCHAR));
474 if (res != ERROR_SUCCESS) goto error_close_key;
476 StringFromGUID2(list->subtype, buf, 39);
477 res = RegSetValueExW(extension_key, subtype_valuename, 0, REG_SZ, (CONST BYTE*)buf,
478 (lstrlenW(buf) + 1) * sizeof(WCHAR));
479 if (res != ERROR_SUCCESS) goto error_close_key;
481 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
482 res = RegSetValueExW(extension_key, sourcefilter_valuename, 0, REG_SZ, (CONST BYTE*)buf,
483 (lstrlenW(buf) + 1) * sizeof(WCHAR));
484 if (res != ERROR_SUCCESS) goto error_close_key;
486 error_close_key:
487 RegCloseKey(extension_key);
490 error_return:
491 RegCloseKey(mediatype_key);
492 if (extensions_root_key)
493 RegCloseKey(extensions_root_key);
495 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
498 /***********************************************************************
499 * unregister_mediatypes_parsing
501 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
503 LONG res;
504 HKEY mediatype_key;
505 HKEY majortype_key;
506 WCHAR buf[39];
508 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
509 KEY_READ | KEY_WRITE, &mediatype_key);
510 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
511 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
513 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
514 StringFromGUID2(list->majortype, buf, 39);
515 res = RegOpenKeyExW(mediatype_key, buf, 0,
516 KEY_READ | KEY_WRITE, &majortype_key);
517 if (res == ERROR_FILE_NOT_FOUND) {
518 res = ERROR_SUCCESS;
519 continue;
521 if (res != ERROR_SUCCESS) break;
523 StringFromGUID2(list->subtype, buf, 39);
524 res = recursive_delete_keyW(majortype_key, buf);
525 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
527 /* Removed majortype key if there is no more subtype key */
528 res = RegDeleteKeyW(majortype_key, 0);
529 if (res == ERROR_ACCESS_DENIED) res = ERROR_SUCCESS;
531 RegCloseKey(majortype_key);
534 RegCloseKey(mediatype_key);
536 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
539 /***********************************************************************
540 * unregister_mediatypes_extension
542 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list)
544 LONG res;
545 HKEY mediatype_key;
546 HKEY extensions_root_key = NULL;
548 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
549 KEY_READ | KEY_WRITE, &mediatype_key);
550 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
551 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
553 res = RegOpenKeyExW(mediatype_key, extensions_keyname, 0,
554 KEY_READ | KEY_WRITE, &extensions_root_key);
555 if (res == ERROR_FILE_NOT_FOUND)
556 res = ERROR_SUCCESS;
557 else if (res == ERROR_SUCCESS)
558 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
559 res = recursive_delete_keyA(extensions_root_key, list->extension);
560 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
563 RegCloseKey(mediatype_key);
564 if (extensions_root_key)
565 RegCloseKey(extensions_root_key);
567 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
570 /***********************************************************************
571 * register_filters
573 static HRESULT register_filters(struct regsvr_filter const *list)
575 HRESULT hr;
576 IFilterMapper2* pFM2 = NULL;
578 CoInitialize(NULL);
579 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
581 if (SUCCEEDED(hr)) {
582 for (; SUCCEEDED(hr) && list->clsid; ++list) {
583 REGFILTER2 rf2;
584 REGFILTERPINS2* prfp2;
585 int i;
587 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
588 rf2.dwVersion = 2;
589 rf2.dwMerit = list->merit;
590 rf2.u.s1.cPins2 = i;
591 rf2.u.s1.rgPins2 = prfp2 = CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
592 if (!prfp2) {
593 hr = E_OUTOFMEMORY;
594 break;
596 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
597 REGPINTYPES* lpMediatype;
598 CLSID* lpClsid;
599 int j, nbmt;
601 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
602 /* Allocate a single buffer for regpintypes struct and clsids */
603 lpMediatype = CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
604 if (!lpMediatype) {
605 hr = E_OUTOFMEMORY;
606 break;
608 lpClsid = (CLSID*) (lpMediatype + nbmt);
609 for (j = 0; j < nbmt; j++) {
610 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
611 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
612 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
613 if (list->pins[i].mediatypes[j].subtype)
614 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
615 else {
616 /* Subtype are often a combination of major type + fourcc/tag */
617 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
618 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
621 prfp2[i].dwFlags = list->pins[i].flags;
622 prfp2[i].cInstances = 0;
623 prfp2[i].nMediaTypes = j;
624 prfp2[i].lpMediaType = lpMediatype;
625 prfp2[i].nMediums = 0;
626 prfp2[i].lpMedium = NULL;
627 prfp2[i].clsPinCategory = NULL;
630 if (FAILED(hr)) {
631 ERR("failed to register with hresult 0x%x\n", hr);
632 CoTaskMemFree(prfp2);
633 break;
636 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
638 while (i) {
639 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
640 i--;
642 CoTaskMemFree(prfp2);
646 if (pFM2)
647 IFilterMapper2_Release(pFM2);
649 CoUninitialize();
651 return hr;
654 /***********************************************************************
655 * unregister_filters
657 static HRESULT unregister_filters(struct regsvr_filter const *list)
659 HRESULT hr;
660 IFilterMapper2* pFM2;
662 CoInitialize(NULL);
664 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
666 if (SUCCEEDED(hr)) {
667 for (; SUCCEEDED(hr) && list->clsid; ++list)
668 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
669 IFilterMapper2_Release(pFM2);
672 CoUninitialize();
674 return hr;
677 /***********************************************************************
678 * regsvr_key_guid
680 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
682 WCHAR buf[39];
684 StringFromGUID2(guid, buf, 39);
685 return register_key_defvalueW(base, name, buf);
688 /***********************************************************************
689 * regsvr_key_defvalueW
691 static LONG register_key_defvalueW(
692 HKEY base,
693 WCHAR const *name,
694 WCHAR const *value)
696 LONG res;
697 HKEY key;
699 res = RegCreateKeyExW(base, name, 0, NULL, 0,
700 KEY_READ | KEY_WRITE, NULL, &key, NULL);
701 if (res != ERROR_SUCCESS) return res;
702 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
703 (lstrlenW(value) + 1) * sizeof(WCHAR));
704 RegCloseKey(key);
705 return res;
708 /***********************************************************************
709 * regsvr_key_defvalueA
711 static LONG register_key_defvalueA(
712 HKEY base,
713 WCHAR const *name,
714 char const *value)
716 LONG res;
717 HKEY key;
719 res = RegCreateKeyExW(base, name, 0, NULL, 0,
720 KEY_READ | KEY_WRITE, NULL, &key, NULL);
721 if (res != ERROR_SUCCESS) return res;
722 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
723 lstrlenA(value) + 1);
724 RegCloseKey(key);
725 return res;
728 /***********************************************************************
729 * regsvr_progid
731 static LONG register_progid(
732 WCHAR const *clsid,
733 char const *progid,
734 char const *curver_progid,
735 char const *name,
736 char const *extra)
738 LONG res;
739 HKEY progid_key;
741 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
742 NULL, 0, KEY_READ | KEY_WRITE, NULL,
743 &progid_key, NULL);
744 if (res != ERROR_SUCCESS) return res;
746 if (name) {
747 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
748 (CONST BYTE*)name, strlen(name) + 1);
749 if (res != ERROR_SUCCESS) goto error_close_progid_key;
752 if (clsid) {
753 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
754 if (res != ERROR_SUCCESS) goto error_close_progid_key;
757 if (curver_progid) {
758 res = register_key_defvalueA(progid_key, curver_keyname,
759 curver_progid);
760 if (res != ERROR_SUCCESS) goto error_close_progid_key;
763 if (extra) {
764 HKEY extra_key;
766 res = RegCreateKeyExA(progid_key, extra, 0,
767 NULL, 0, KEY_READ | KEY_WRITE, NULL,
768 &extra_key, NULL);
769 if (res == ERROR_SUCCESS)
770 RegCloseKey(extra_key);
773 error_close_progid_key:
774 RegCloseKey(progid_key);
775 return res;
778 /***********************************************************************
779 * recursive_delete_key
781 static LONG recursive_delete_key(HKEY key)
783 LONG res;
784 WCHAR subkey_name[MAX_PATH];
785 DWORD cName;
786 HKEY subkey;
788 for (;;) {
789 cName = sizeof(subkey_name) / sizeof(WCHAR);
790 res = RegEnumKeyExW(key, 0, subkey_name, &cName,
791 NULL, NULL, NULL, NULL);
792 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) {
793 res = ERROR_SUCCESS; /* presumably we're done enumerating */
794 break;
796 res = RegOpenKeyExW(key, subkey_name, 0,
797 KEY_READ | KEY_WRITE, &subkey);
798 if (res == ERROR_FILE_NOT_FOUND) continue;
799 if (res != ERROR_SUCCESS) break;
801 res = recursive_delete_key(subkey);
802 RegCloseKey(subkey);
803 if (res != ERROR_SUCCESS) break;
806 if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0);
807 return res;
810 /***********************************************************************
811 * recursive_delete_keyA
813 static LONG recursive_delete_keyA(HKEY base, char const *name)
815 LONG res;
816 HKEY key;
818 res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key);
819 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
820 if (res != ERROR_SUCCESS) return res;
821 res = recursive_delete_key(key);
822 RegCloseKey(key);
823 return res;
826 /***********************************************************************
827 * recursive_delete_keyW
829 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name)
831 LONG res;
832 HKEY key;
834 res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key);
835 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
836 if (res != ERROR_SUCCESS) return res;
837 res = recursive_delete_key(key);
838 RegCloseKey(key);
839 return res;
843 static GUID const CLSID_PSFactoryBuffer = {
844 0x92a3a302, 0xda7c, 0x4a1f, {0xba,0x7e,0x18,0x02,0xbb,0x5d,0x2d,0x02} };
846 /***********************************************************************
847 * coclass list
849 static struct regsvr_coclass const coclass_list[] = {
850 { &CLSID_FilterGraph,
851 "Filter Graph",
852 NULL,
853 "quartz.dll",
854 "Both"
856 { &CLSID_FilterGraphNoThread,
857 "Filter Graph",
858 NULL,
859 "quartz.dll",
860 "Both"
862 { &CLSID_FilterMapper,
863 "Filter Mapper",
864 NULL,
865 "quartz.dll",
866 "Both"
868 { &CLSID_FilterMapper2,
869 "Filter Mapper2",
870 NULL,
871 "quartz.dll",
872 "Both"
874 { &CLSID_SystemClock,
875 "System Clock",
876 NULL,
877 "quartz.dll",
878 "Both"
880 { &CLSID_MemoryAllocator,
881 "Memory Allocator",
882 NULL,
883 "quartz.dll",
884 "Both"
886 { &CLSID_SeekingPassThru,
887 "Seeking",
888 NULL,
889 "quartz.dll",
890 "Both"
892 { &CLSID_AsyncReader,
893 "File Source Filter",
894 NULL,
895 "quartz.dll",
896 "Both"
898 { &CLSID_AviSplitter,
899 "AVI Splitter",
900 NULL,
901 "quartz.dll",
902 "Both"
904 { &CLSID_MPEG1Splitter,
905 "MPEG-I Stream Splitter",
906 NULL,
907 "quartz.dll",
908 "Both"
910 { &CLSID_AVIDec,
911 "AVI Decompressor",
912 NULL,
913 "quartz.dll",
914 "Both"
916 { &CLSID_DSoundRender,
917 "DirectSound Audio Renderer",
918 NULL,
919 "quartz.dll",
920 "Both"
922 { &CLSID_VideoRenderer,
923 "Video Renderer",
924 NULL,
925 "quartz.dll",
926 "Both"
928 { &CLSID_ACMWrapper,
929 "ACM wrapper",
930 NULL,
931 "quartz.dll",
932 "Both"
934 { &CLSID_WAVEParser,
935 "Wave Parser",
936 NULL,
937 "quartz.dll",
938 "Both"
940 { NULL } /* list terminator */
943 /***********************************************************************
944 * interface list
947 static struct regsvr_interface const interface_list[] = {
948 { &IID_IFilterGraph,
949 "IFilterGraph",
950 NULL,
952 NULL,
953 &CLSID_PSFactoryBuffer
955 { &IID_IFilterGraph2,
956 "IFilterGraph2",
957 NULL,
959 NULL,
960 &CLSID_PSFactoryBuffer
962 { &IID_IFilterMapper,
963 "IFilterMapper",
964 NULL,
966 NULL,
967 &CLSID_PSFactoryBuffer
969 { &IID_IFilterMapper2,
970 "IFilterMapper2",
971 NULL,
973 NULL,
974 &CLSID_PSFactoryBuffer
976 /* FIXME:
977 { &IID_SeekingPassThru,
978 "ISeekingPassThru",
979 NULL,
981 NULL,
982 &CLSID_PSFactoryBuffer
984 { &IID_AsyncReader,
985 "IAsyncReader",
986 NULL,
988 NULL,
989 &CLSID_PSFactoryBuffer
991 { &IID_WAVEParser,
992 "IWAVEParser",
993 NULL,
995 NULL,
996 &CLSID_PSFactoryBuffer
997 },*/
998 { NULL } /* list terminator */
1001 /***********************************************************************
1002 * mediatype list
1005 static struct regsvr_mediatype_parsing const mediatype_parsing_list[] = {
1006 { &MEDIATYPE_Stream,
1007 &MEDIASUBTYPE_Avi,
1008 { "0,4,,52494646,8,4,,41564920",
1009 NULL }
1011 { &MEDIATYPE_Stream,
1012 &MEDIASUBTYPE_MPEG1System,
1013 { "0, 16, FFFFFFFFF100010001800001FFFFFFFF, 000001BA2100010001800001000001BB",
1014 NULL }
1016 { &MEDIATYPE_Stream,
1017 &MEDIASUBTYPE_MPEG1VideoCD,
1018 { "0, 4, , 52494646, 8, 8, , 43445841666D7420, 36, 20, FFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF, 646174610000000000FFFFFFFFFFFFFFFFFFFF00",
1019 NULL }
1021 { &MEDIATYPE_Stream,
1022 &MEDIASUBTYPE_MPEG1Video,
1023 { "0, 4, , 000001B3",
1024 NULL }
1026 { &MEDIATYPE_Stream,
1027 &MEDIASUBTYPE_MPEG1Audio,
1028 { "0, 2, FFE0, FFE0",
1029 "0, 10, FFFFFFFF000000000000, 494433030080808080",
1030 NULL }
1032 { &MEDIATYPE_Stream,
1033 &MEDIASUBTYPE_QTMovie,
1034 { "4, 4, , 6d646174",
1035 "4, 4, , 6d6f6f76",
1036 NULL }
1038 { &MEDIATYPE_Stream,
1039 &MEDIASUBTYPE_WAVE,
1040 { "0,4,,52494646,8,4,,57415645",
1041 NULL }
1043 { &MEDIATYPE_Stream,
1044 &MEDIASUBTYPE_AU,
1045 { "0,4,,2e736e64",
1046 NULL }
1048 { &MEDIATYPE_Stream,
1049 &MEDIASUBTYPE_AIFF,
1050 { "0,4,,464f524d,8,4,,41494646",
1051 "0,4,,464f524d,8,4,,41494643",
1052 NULL }
1054 { &MEDIATYPE_Stream,
1055 &MEDIATYPE_Text,
1056 { "0,4,,4C595249",
1057 "0,4,,6C797269",
1058 NULL }
1060 { &MEDIATYPE_Stream,
1061 &MEDIATYPE_Midi,
1062 { "0,4,,52494646,8,4,,524D4944",
1063 "0,4,,4D546864",
1064 NULL }
1066 { NULL } /* list terminator */
1069 /***********************************************************************
1070 * mediatype list
1073 static struct regsvr_mediatype_extension const mediatype_extension_list[] = {
1074 { &MEDIATYPE_Stream,
1075 &MEDIASUBTYPE_MPEG1Audio,
1076 ".mp3"
1078 { NULL } /* list terminator */
1081 /***********************************************************************
1082 * filter list
1085 static struct regsvr_filter const filter_list[] = {
1086 { &CLSID_AviSplitter,
1087 &CLSID_LegacyAmFilterCategory,
1088 {'A','V','I',' ','S','p','l','i','t','t','e','r',0},
1089 0x600000,
1090 { { 0,
1091 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_Avi },
1092 { NULL }
1095 { REG_PINFLAG_B_OUTPUT,
1096 { { &MEDIATYPE_Video, &GUID_NULL },
1097 { NULL }
1100 { 0xFFFFFFFF },
1103 { &CLSID_MPEG1Splitter,
1104 &CLSID_LegacyAmFilterCategory,
1105 {'M','P','E','G','-','I',' ','S','t','r','e','a','m',' ','S','p','l','i','t','t','e','r',0},
1106 0x600000,
1107 { { 0,
1108 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Audio },
1109 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Video },
1110 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1System },
1111 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1VideoCD },
1112 { NULL }
1115 { REG_PINFLAG_B_OUTPUT,
1116 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1Packet },
1117 { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1AudioPayload },
1118 { NULL }
1121 { REG_PINFLAG_B_OUTPUT,
1122 { { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Packet },
1123 { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Payload },
1124 { NULL }
1127 { 0xFFFFFFFF },
1130 { &CLSID_VideoRenderer,
1131 &CLSID_LegacyAmFilterCategory,
1132 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
1133 0x800000,
1134 { { REG_PINFLAG_B_RENDERER,
1135 { { &MEDIATYPE_Video, &GUID_NULL },
1136 { NULL }
1139 { 0xFFFFFFFF },
1142 { &CLSID_AVIDec,
1143 &CLSID_LegacyAmFilterCategory,
1144 {'A','V','I',' ','D','e','c','o','m','p','r','e','s','s','o','r',0},
1145 0x600000,
1146 { { 0,
1147 { { &MEDIATYPE_Video, &GUID_NULL },
1148 { NULL }
1151 { REG_PINFLAG_B_OUTPUT,
1152 { { &MEDIATYPE_Video, &GUID_NULL },
1153 { NULL }
1156 { 0xFFFFFFFF },
1159 { &CLSID_AsyncReader,
1160 &CLSID_LegacyAmFilterCategory,
1161 {'F','i','l','e',' ','S','o','u','r','c','e',' ','(','A','s','y','n','c','.',')',0},
1162 0x400000,
1163 { { REG_PINFLAG_B_OUTPUT,
1164 { { &MEDIATYPE_Stream, &GUID_NULL },
1165 { NULL }
1168 { 0xFFFFFFFF },
1171 { &CLSID_ACMWrapper,
1172 &CLSID_LegacyAmFilterCategory,
1173 {'A','C','M',' ','W','r','a','p','p','e','r',0},
1174 0x600000,
1175 { { 0,
1176 { { &MEDIATYPE_Audio, &GUID_NULL },
1177 { NULL }
1180 { REG_PINFLAG_B_OUTPUT,
1181 { { &MEDIATYPE_Audio, &GUID_NULL },
1182 { NULL }
1185 { 0xFFFFFFFF },
1188 { &CLSID_WAVEParser,
1189 &CLSID_LegacyAmFilterCategory,
1190 {'W','a','v','e',' ','P','a','r','s','e','r',0},
1191 0x400000,
1192 { { 0,
1193 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE },
1194 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AU },
1195 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AIFF },
1196 { NULL }
1199 { REG_PINFLAG_B_OUTPUT,
1200 { { &MEDIATYPE_Audio, &GUID_NULL },
1201 { NULL }
1204 { 0xFFFFFFFF },
1207 { NULL } /* list terminator */
1210 /***********************************************************************
1211 * DllRegisterServer (QUARTZ.@)
1213 HRESULT WINAPI DllRegisterServer(void)
1215 HRESULT hr;
1217 TRACE("\n");
1219 hr = register_coclasses(coclass_list);
1220 if (SUCCEEDED(hr))
1221 hr = register_interfaces(interface_list);
1222 if (SUCCEEDED(hr))
1223 hr = register_mediatypes_parsing(mediatype_parsing_list);
1224 if (SUCCEEDED(hr))
1225 hr = register_mediatypes_extension(mediatype_extension_list);
1226 if (SUCCEEDED(hr))
1227 hr = register_filters(filter_list);
1228 return hr;
1231 /***********************************************************************
1232 * DllUnregisterServer (QUARTZ.@)
1234 HRESULT WINAPI DllUnregisterServer(void)
1236 HRESULT hr;
1238 TRACE("\n");
1240 hr = unregister_filters(filter_list);
1241 if (SUCCEEDED(hr))
1242 hr = unregister_coclasses(coclass_list);
1243 if (SUCCEEDED(hr))
1244 hr = unregister_interfaces(interface_list);
1245 if (SUCCEEDED(hr))
1246 hr = unregister_mediatypes_parsing(mediatype_parsing_list);
1247 if (SUCCEEDED(hr))
1248 hr = unregister_mediatypes_extension(mediatype_extension_list);
1249 return hr;