Release 20050930.
[wine/gsoc-2012-control.git] / dlls / quartz / regsvr.c
blob385120b1841bd1f12ae8898acea4b1bf665d5e5f
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
24 #define COM_NO_WINDOWS_H
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "uuids.h"
36 #include "strmif.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
43 * Near the bottom of this file are the exported DllRegisterServer and
44 * DllUnregisterServer, which make all this worthwhile.
47 /***********************************************************************
48 * interface for self-registering
50 struct regsvr_interface
52 IID const *iid; /* NULL for end of list */
53 LPCSTR name; /* can be NULL to omit */
54 IID const *base_iid; /* can be NULL to omit */
55 int num_methods; /* can be <0 to omit */
56 CLSID const *ps_clsid; /* can be NULL to omit */
57 CLSID const *ps_clsid32; /* can be NULL to omit */
60 static HRESULT register_interfaces(struct regsvr_interface const *list);
61 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
63 struct regsvr_coclass
65 CLSID const *clsid; /* NULL for end of list */
66 LPCSTR name; /* can be NULL to omit */
67 LPCSTR ips; /* can be NULL to omit */
68 LPCSTR ips32; /* can be NULL to omit */
69 LPCSTR ips32_tmodel; /* can be NULL to omit */
70 LPCSTR progid; /* can be NULL to omit */
71 LPCSTR viprogid; /* can be NULL to omit */
72 LPCSTR progid_extra; /* can be NULL to omit */
75 static HRESULT register_coclasses(struct regsvr_coclass const *list);
76 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
78 struct regsvr_mediatype_parsing
80 CLSID const *majortype; /* NULL for end of list */
81 CLSID const *subtype;
82 LPCSTR line[11]; /* NULL for end of list */
85 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
86 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
88 struct regsvr_mediatype_extension
90 CLSID const *majortype; /* NULL for end of list */
91 CLSID const *subtype;
92 LPCSTR extension;
95 struct mediatype
97 CLSID const *majortype; /* NULL for end of list */
98 CLSID const *subtype;
99 DWORD fourcc;
102 struct pin
104 DWORD flags; /* 0xFFFFFFFF for end of list */
105 struct mediatype mediatypes[11];
108 struct regsvr_filter
110 CLSID const *clsid; /* NULL for end of list */
111 CLSID const *category;
112 WCHAR name[50];
113 DWORD merit;
114 struct pin pins[11];
117 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list);
118 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list);
120 static HRESULT register_filters(struct regsvr_filter const *list);
121 static HRESULT unregister_filters(struct regsvr_filter const *list);
123 /***********************************************************************
124 * static string constants
126 static WCHAR const interface_keyname[10] = {
127 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
128 static WCHAR const base_ifa_keyname[14] = {
129 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
130 'e', 0 };
131 static WCHAR const num_methods_keyname[11] = {
132 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
133 static WCHAR const ps_clsid_keyname[15] = {
134 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
135 'i', 'd', 0 };
136 static WCHAR const ps_clsid32_keyname[17] = {
137 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
138 'i', 'd', '3', '2', 0 };
139 static WCHAR const clsid_keyname[6] = {
140 'C', 'L', 'S', 'I', 'D', 0 };
141 static WCHAR const curver_keyname[7] = {
142 'C', 'u', 'r', 'V', 'e', 'r', 0 };
143 static WCHAR const ips_keyname[13] = {
144 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
145 0 };
146 static WCHAR const ips32_keyname[15] = {
147 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
148 '3', '2', 0 };
149 static WCHAR const progid_keyname[7] = {
150 'P', 'r', 'o', 'g', 'I', 'D', 0 };
151 static WCHAR const viprogid_keyname[25] = {
152 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
153 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
154 0 };
155 static char const tmodel_valuename[] = "ThreadingModel";
156 static WCHAR const mediatype_name[11] = {
157 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
158 static WCHAR const subtype_valuename[8] = {
159 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
160 static WCHAR const sourcefilter_valuename[14] = {
161 'S', 'o', 'u', 'r', 'c', 'e', ' ', 'F', 'i', 'l', 't', 'e', 'r', 0 };
162 static WCHAR const extensions_keyname[11] = {
163 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', 0 };
165 /***********************************************************************
166 * static helper functions
168 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
169 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
170 WCHAR const *value);
171 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
172 char const *value);
173 static LONG register_progid(WCHAR const *clsid,
174 char const *progid, char const *curver_progid,
175 char const *name, char const *extra);
176 static LONG recursive_delete_key(HKEY key);
177 static LONG recursive_delete_keyA(HKEY base, char const *name);
178 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name);
180 /***********************************************************************
181 * register_interfaces
183 static HRESULT register_interfaces(struct regsvr_interface const *list)
185 LONG res = ERROR_SUCCESS;
186 HKEY interface_key;
188 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
189 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
190 if (res != ERROR_SUCCESS) goto error_return;
192 for (; res == ERROR_SUCCESS && list->iid; ++list) {
193 WCHAR buf[39];
194 HKEY iid_key;
196 StringFromGUID2(list->iid, buf, 39);
197 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
198 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
199 if (res != ERROR_SUCCESS) goto error_close_interface_key;
201 if (list->name) {
202 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
203 (CONST BYTE*)(list->name),
204 strlen(list->name) + 1);
205 if (res != ERROR_SUCCESS) goto error_close_iid_key;
208 if (list->base_iid) {
209 register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
210 if (res != ERROR_SUCCESS) goto error_close_iid_key;
213 if (0 <= list->num_methods) {
214 static WCHAR const fmt[3] = { '%', 'd', 0 };
215 HKEY key;
217 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
218 KEY_READ | KEY_WRITE, NULL, &key, NULL);
219 if (res != ERROR_SUCCESS) goto error_close_iid_key;
221 wsprintfW(buf, fmt, list->num_methods);
222 res = RegSetValueExW(key, NULL, 0, REG_SZ,
223 (CONST BYTE*)buf,
224 (lstrlenW(buf) + 1) * sizeof(WCHAR));
225 RegCloseKey(key);
227 if (res != ERROR_SUCCESS) goto error_close_iid_key;
230 if (list->ps_clsid) {
231 register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
232 if (res != ERROR_SUCCESS) goto error_close_iid_key;
235 if (list->ps_clsid32) {
236 register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
237 if (res != ERROR_SUCCESS) goto error_close_iid_key;
240 error_close_iid_key:
241 RegCloseKey(iid_key);
244 error_close_interface_key:
245 RegCloseKey(interface_key);
246 error_return:
247 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
250 /***********************************************************************
251 * unregister_interfaces
253 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
255 LONG res = ERROR_SUCCESS;
256 HKEY interface_key;
258 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
259 KEY_READ | KEY_WRITE, &interface_key);
260 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
261 if (res != ERROR_SUCCESS) goto error_return;
263 for (; res == ERROR_SUCCESS && list->iid; ++list) {
264 WCHAR buf[39];
266 StringFromGUID2(list->iid, buf, 39);
267 res = recursive_delete_keyW(interface_key, buf);
270 RegCloseKey(interface_key);
271 error_return:
272 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
275 /***********************************************************************
276 * register_coclasses
278 static HRESULT register_coclasses(struct regsvr_coclass const *list)
280 LONG res = ERROR_SUCCESS;
281 HKEY coclass_key;
283 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
284 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
285 if (res != ERROR_SUCCESS) goto error_return;
287 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
288 WCHAR buf[39];
289 HKEY clsid_key;
291 StringFromGUID2(list->clsid, buf, 39);
292 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
293 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
294 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
296 if (list->name) {
297 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
298 (CONST BYTE*)(list->name),
299 strlen(list->name) + 1);
300 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
303 if (list->ips) {
304 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
305 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
308 if (list->ips32) {
309 HKEY ips32_key;
311 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
312 KEY_READ | KEY_WRITE, NULL,
313 &ips32_key, NULL);
314 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
316 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
317 (CONST BYTE*)list->ips32,
318 lstrlenA(list->ips32) + 1);
319 if (res == ERROR_SUCCESS && list->ips32_tmodel)
320 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
321 (CONST BYTE*)list->ips32_tmodel,
322 strlen(list->ips32_tmodel) + 1);
323 RegCloseKey(ips32_key);
324 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
327 if (list->progid) {
328 res = register_key_defvalueA(clsid_key, progid_keyname,
329 list->progid);
330 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
332 res = register_progid(buf, list->progid, NULL,
333 list->name, list->progid_extra);
334 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
337 if (list->viprogid) {
338 res = register_key_defvalueA(clsid_key, viprogid_keyname,
339 list->viprogid);
340 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
342 res = register_progid(buf, list->viprogid, list->progid,
343 list->name, list->progid_extra);
344 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
347 error_close_clsid_key:
348 RegCloseKey(clsid_key);
351 error_close_coclass_key:
352 RegCloseKey(coclass_key);
353 error_return:
354 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
357 /***********************************************************************
358 * unregister_coclasses
360 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
362 LONG res = ERROR_SUCCESS;
363 HKEY coclass_key;
365 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
366 KEY_READ | KEY_WRITE, &coclass_key);
367 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
368 if (res != ERROR_SUCCESS) goto error_return;
370 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
371 WCHAR buf[39];
373 StringFromGUID2(list->clsid, buf, 39);
374 res = recursive_delete_keyW(coclass_key, buf);
375 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
377 if (list->progid) {
378 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->progid);
379 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
382 if (list->viprogid) {
383 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->viprogid);
384 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
388 error_close_coclass_key:
389 RegCloseKey(coclass_key);
390 error_return:
391 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
394 /***********************************************************************
395 * register_mediatypes_parsing
397 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
399 LONG res = ERROR_SUCCESS;
400 HKEY mediatype_key;
401 WCHAR buf[39];
402 int i;
404 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
405 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
406 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
408 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
409 HKEY majortype_key = NULL;
410 HKEY subtype_key = NULL;
412 StringFromGUID2(list->majortype, buf, 39);
413 res = RegCreateKeyExW(mediatype_key, buf, 0, NULL, 0,
414 KEY_READ | KEY_WRITE, NULL, &majortype_key, NULL);
415 if (res != ERROR_SUCCESS) goto error_close_keys;
417 StringFromGUID2(list->subtype, buf, 39);
418 res = RegCreateKeyExW(majortype_key, buf, 0, NULL, 0,
419 KEY_READ | KEY_WRITE, NULL, &subtype_key, NULL);
420 if (res != ERROR_SUCCESS) goto error_close_keys;
422 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
423 res = RegSetValueExW(subtype_key, sourcefilter_valuename, 0, REG_SZ, (CONST BYTE*)buf,
424 (lstrlenW(buf) + 1) * sizeof(WCHAR));
425 if (res != ERROR_SUCCESS) goto error_close_keys;
427 for(i = 0; list->line[i]; i++) {
428 char buffer[3];
429 wsprintfA(buffer, "%d", i);
430 res = RegSetValueExA(subtype_key, buffer, 0, REG_SZ, (CONST BYTE*)list->line[i],
431 lstrlenA(list->line[i]));
432 if (res != ERROR_SUCCESS) goto error_close_keys;
435 error_close_keys:
436 if (majortype_key)
437 RegCloseKey(majortype_key);
438 if (subtype_key)
439 RegCloseKey(subtype_key);
442 RegCloseKey(mediatype_key);
444 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
447 /***********************************************************************
448 * register_mediatypes_extension
450 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list)
452 LONG res = ERROR_SUCCESS;
453 HKEY mediatype_key;
454 HKEY extensions_root_key = NULL;
455 WCHAR buf[39];
457 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
458 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
459 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
461 res = RegCreateKeyExW(mediatype_key, extensions_keyname, 0, NULL, 0,
462 KEY_READ | KEY_WRITE, NULL, &extensions_root_key, NULL);
463 if (res != ERROR_SUCCESS) goto error_return;
465 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
466 HKEY extension_key;
468 res = RegCreateKeyExA(extensions_root_key, list->extension, 0, NULL, 0,
469 KEY_READ | KEY_WRITE, NULL, &extension_key, NULL);
470 if (res != ERROR_SUCCESS) break;
472 StringFromGUID2(list->majortype, buf, 39);
473 res = RegSetValueExW(extension_key, mediatype_name, 0, REG_SZ, (CONST BYTE*)buf,
474 (lstrlenW(buf) + 1) * sizeof(WCHAR));
475 if (res != ERROR_SUCCESS) goto error_close_key;
477 StringFromGUID2(list->subtype, buf, 39);
478 res = RegSetValueExW(extension_key, subtype_valuename, 0, REG_SZ, (CONST BYTE*)buf,
479 (lstrlenW(buf) + 1) * sizeof(WCHAR));
480 if (res != ERROR_SUCCESS) goto error_close_key;
482 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
483 res = RegSetValueExW(extension_key, sourcefilter_valuename, 0, REG_SZ, (CONST BYTE*)buf,
484 (lstrlenW(buf) + 1) * sizeof(WCHAR));
485 if (res != ERROR_SUCCESS) goto error_close_key;
487 error_close_key:
488 RegCloseKey(extension_key);
491 error_return:
492 RegCloseKey(mediatype_key);
493 if (extensions_root_key)
494 RegCloseKey(extensions_root_key);
496 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
499 /***********************************************************************
500 * unregister_mediatypes_parsing
502 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
504 LONG res;
505 HKEY mediatype_key;
506 HKEY majortype_key;
507 WCHAR buf[39];
509 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
510 KEY_READ | KEY_WRITE, &mediatype_key);
511 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
512 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
514 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
515 StringFromGUID2(list->majortype, buf, 39);
516 res = RegOpenKeyExW(mediatype_key, buf, 0,
517 KEY_READ | KEY_WRITE, &majortype_key);
518 if (res == ERROR_FILE_NOT_FOUND) {
519 res = ERROR_SUCCESS;
520 continue;
522 if (res != ERROR_SUCCESS) break;
524 StringFromGUID2(list->subtype, buf, 39);
525 res = recursive_delete_keyW(majortype_key, buf);
526 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
528 /* Removed majortype key if there is no more subtype key */
529 res = RegDeleteKeyW(majortype_key, 0);
530 if (res == ERROR_ACCESS_DENIED) res = ERROR_SUCCESS;
532 RegCloseKey(majortype_key);
535 RegCloseKey(mediatype_key);
537 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
540 /***********************************************************************
541 * unregister_mediatypes_extension
543 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list)
545 LONG res;
546 HKEY mediatype_key;
547 HKEY extensions_root_key = NULL;
549 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
550 KEY_READ | KEY_WRITE, &mediatype_key);
551 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
552 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
554 res = RegOpenKeyExW(mediatype_key, extensions_keyname, 0,
555 KEY_READ | KEY_WRITE, &extensions_root_key);
556 if (res == ERROR_FILE_NOT_FOUND)
557 res = ERROR_SUCCESS;
558 else if (res == ERROR_SUCCESS)
559 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
560 res = recursive_delete_keyA(extensions_root_key, list->extension);
561 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
564 RegCloseKey(mediatype_key);
565 if (extensions_root_key)
566 RegCloseKey(extensions_root_key);
568 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
571 /***********************************************************************
572 * register_filters
574 static HRESULT register_filters(struct regsvr_filter const *list)
576 HRESULT hr;
577 IFilterMapper2* pFM2 = NULL;
579 CoInitialize(NULL);
580 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
582 if (SUCCEEDED(hr)) {
583 for (; SUCCEEDED(hr) && list->clsid; ++list) {
584 REGFILTER2 rf2;
585 REGFILTERPINS2* prfp2;
586 int i;
588 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
589 rf2.dwVersion = 2;
590 rf2.dwMerit = list->merit;
591 rf2.u.s1.cPins2 = i;
592 rf2.u.s1.rgPins2 = prfp2 = (REGFILTERPINS2*) CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
593 if (!prfp2) {
594 hr = E_OUTOFMEMORY;
595 break;
597 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
598 REGPINTYPES* lpMediatype;
599 CLSID* lpClsid;
600 int j, nbmt;
602 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
603 /* Allocate a single buffer for regpintypes struct and clsids */
604 lpMediatype = (REGPINTYPES*) CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
605 if (!lpMediatype) {
606 hr = E_OUTOFMEMORY;
607 break;
609 lpClsid = (CLSID*) (lpMediatype + nbmt);
610 for (j = 0; j < nbmt; j++) {
611 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
612 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
613 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
614 if (list->pins[i].mediatypes[j].subtype)
615 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
616 else {
617 /* Subtype are often a combination of major type + fourcc/tag */
618 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
619 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
622 prfp2[i].dwFlags = list->pins[i].flags;
623 prfp2[i].cInstances = 0;
624 prfp2[i].nMediaTypes = j;
625 prfp2[i].lpMediaType = lpMediatype;
626 prfp2[i].nMediums = 0;
627 prfp2[i].lpMedium = NULL;
628 prfp2[i].clsPinCategory = NULL;
631 if (FAILED(hr)) {
632 ERR("failed to register with hresult 0x%lx\n", hr);
633 CoTaskMemFree(prfp2);
634 break;
637 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
639 while (i) {
640 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
641 i--;
643 CoTaskMemFree(prfp2);
647 if (pFM2)
648 IFilterMapper2_Release(pFM2);
650 CoUninitialize();
652 return hr;
655 /***********************************************************************
656 * unregister_filters
658 static HRESULT unregister_filters(struct regsvr_filter const *list)
660 HRESULT hr;
661 IFilterMapper2* pFM2;
663 CoInitialize(NULL);
665 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
667 if (SUCCEEDED(hr)) {
668 for (; SUCCEEDED(hr) && list->clsid; ++list)
669 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
670 IFilterMapper2_Release(pFM2);
673 CoUninitialize();
675 return hr;
678 /***********************************************************************
679 * regsvr_key_guid
681 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
683 WCHAR buf[39];
685 StringFromGUID2(guid, buf, 39);
686 return register_key_defvalueW(base, name, buf);
689 /***********************************************************************
690 * regsvr_key_defvalueW
692 static LONG register_key_defvalueW(
693 HKEY base,
694 WCHAR const *name,
695 WCHAR const *value)
697 LONG res;
698 HKEY key;
700 res = RegCreateKeyExW(base, name, 0, NULL, 0,
701 KEY_READ | KEY_WRITE, NULL, &key, NULL);
702 if (res != ERROR_SUCCESS) return res;
703 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
704 (lstrlenW(value) + 1) * sizeof(WCHAR));
705 RegCloseKey(key);
706 return res;
709 /***********************************************************************
710 * regsvr_key_defvalueA
712 static LONG register_key_defvalueA(
713 HKEY base,
714 WCHAR const *name,
715 char const *value)
717 LONG res;
718 HKEY key;
720 res = RegCreateKeyExW(base, name, 0, NULL, 0,
721 KEY_READ | KEY_WRITE, NULL, &key, NULL);
722 if (res != ERROR_SUCCESS) return res;
723 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
724 lstrlenA(value) + 1);
725 RegCloseKey(key);
726 return res;
729 /***********************************************************************
730 * regsvr_progid
732 static LONG register_progid(
733 WCHAR const *clsid,
734 char const *progid,
735 char const *curver_progid,
736 char const *name,
737 char const *extra)
739 LONG res;
740 HKEY progid_key;
742 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
743 NULL, 0, KEY_READ | KEY_WRITE, NULL,
744 &progid_key, NULL);
745 if (res != ERROR_SUCCESS) return res;
747 if (name) {
748 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
749 (CONST BYTE*)name, strlen(name) + 1);
750 if (res != ERROR_SUCCESS) goto error_close_progid_key;
753 if (clsid) {
754 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
755 if (res != ERROR_SUCCESS) goto error_close_progid_key;
758 if (curver_progid) {
759 res = register_key_defvalueA(progid_key, curver_keyname,
760 curver_progid);
761 if (res != ERROR_SUCCESS) goto error_close_progid_key;
764 if (extra) {
765 HKEY extra_key;
767 res = RegCreateKeyExA(progid_key, extra, 0,
768 NULL, 0, KEY_READ | KEY_WRITE, NULL,
769 &extra_key, NULL);
770 if (res == ERROR_SUCCESS)
771 RegCloseKey(extra_key);
774 error_close_progid_key:
775 RegCloseKey(progid_key);
776 return res;
779 /***********************************************************************
780 * recursive_delete_key
782 static LONG recursive_delete_key(HKEY key)
784 LONG res;
785 WCHAR subkey_name[MAX_PATH];
786 DWORD cName;
787 HKEY subkey;
789 for (;;) {
790 cName = sizeof(subkey_name) / sizeof(WCHAR);
791 res = RegEnumKeyExW(key, 0, subkey_name, &cName,
792 NULL, NULL, NULL, NULL);
793 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) {
794 res = ERROR_SUCCESS; /* presumably we're done enumerating */
795 break;
797 res = RegOpenKeyExW(key, subkey_name, 0,
798 KEY_READ | KEY_WRITE, &subkey);
799 if (res == ERROR_FILE_NOT_FOUND) continue;
800 if (res != ERROR_SUCCESS) break;
802 res = recursive_delete_key(subkey);
803 RegCloseKey(subkey);
804 if (res != ERROR_SUCCESS) break;
807 if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0);
808 return res;
811 /***********************************************************************
812 * recursive_delete_keyA
814 static LONG recursive_delete_keyA(HKEY base, char const *name)
816 LONG res;
817 HKEY key;
819 res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key);
820 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
821 if (res != ERROR_SUCCESS) return res;
822 res = recursive_delete_key(key);
823 RegCloseKey(key);
824 return res;
827 /***********************************************************************
828 * recursive_delete_keyW
830 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name)
832 LONG res;
833 HKEY key;
835 res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key);
836 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
837 if (res != ERROR_SUCCESS) return res;
838 res = recursive_delete_key(key);
839 RegCloseKey(key);
840 return res;
843 /***********************************************************************
844 * coclass list
846 static struct regsvr_coclass const coclass_list[] = {
847 { &CLSID_FilterGraph,
848 "Filter Graph",
849 NULL,
850 "quartz.dll",
851 "Both"
853 { &CLSID_FilterGraphNoThread,
854 "Filter Graph",
855 NULL,
856 "quartz.dll",
857 "Both"
859 { &CLSID_FilterMapper,
860 "Filter Mapper",
861 NULL,
862 "quartz.dll",
863 "Both"
865 { &CLSID_FilterMapper2,
866 "Filter Mapper2",
867 NULL,
868 "quartz.dll",
869 "Both"
871 { &CLSID_SystemClock,
872 "System Clock",
873 NULL,
874 "quartz.dll",
875 "Both"
877 { &CLSID_MemoryAllocator,
878 "Memory Allocator",
879 NULL,
880 "quartz.dll",
881 "Both"
883 { &CLSID_SeekingPassThru,
884 "Seeking",
885 NULL,
886 "quartz.dll",
887 "Both"
889 { &CLSID_AsyncReader,
890 "File Source Filter",
891 NULL,
892 "quartz.dll",
893 "Both"
895 { &CLSID_AviSplitter,
896 "AVI Splitter",
897 NULL,
898 "quartz.dll",
899 "Both"
901 { &CLSID_AVIDec,
902 "AVI Decompressor",
903 NULL,
904 "quartz.dll",
905 "Both"
907 { &CLSID_DSoundRender,
908 "DirectSound Audio Renderer",
909 NULL,
910 "quartz.dll",
911 "Both"
913 { &CLSID_VideoRenderer,
914 "Video Renderer",
915 NULL,
916 "quartz.dll",
917 "Both"
919 { &CLSID_ACMWrapper,
920 "ACM wrapper",
921 NULL,
922 "quartz.dll",
923 "Both"
925 { &CLSID_WAVEParser,
926 "Wave Parser",
927 NULL,
928 "quartz.dll",
929 "Both"
931 { NULL } /* list terminator */
934 /***********************************************************************
935 * interface list
938 static struct regsvr_interface const interface_list[] = {
939 { NULL } /* list terminator */
942 /***********************************************************************
943 * mediatype list
946 static struct regsvr_mediatype_parsing const mediatype_parsing_list[] = {
947 { &MEDIATYPE_Stream,
948 &MEDIASUBTYPE_Avi,
949 { "0,4,,52494646,8,4,,41564920",
950 NULL }
952 { &MEDIATYPE_Stream,
953 &MEDIASUBTYPE_MPEG1System,
954 { "0, 16, FFFFFFFFF100010001800001FFFFFFFF, 000001BA2100010001800001000001BB",
955 NULL }
957 { &MEDIATYPE_Stream,
958 &MEDIASUBTYPE_MPEG1VideoCD,
959 { "0, 4, , 52494646, 8, 8, , 43445841666D7420, 36, 20, FFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF, 646174610000000000FFFFFFFFFFFFFFFFFFFF00",
960 NULL }
962 { &MEDIATYPE_Stream,
963 &MEDIASUBTYPE_MPEG1Video,
964 { "0, 4, , 000001B3",
965 NULL }
967 { &MEDIATYPE_Stream,
968 &MEDIASUBTYPE_MPEG1Audio,
969 { "0, 2, FFE0, FFE0",
970 "0, 10, FFFFFFFF000000000000, 494433030080808080",
971 NULL }
973 { &MEDIATYPE_Stream,
974 &MEDIASUBTYPE_QTMovie,
975 { "4, 4, , 6d646174",
976 "4, 4, , 6d6f6f76",
977 NULL }
979 { &MEDIATYPE_Stream,
980 &MEDIASUBTYPE_WAVE,
981 { "0,4,,52494646,8,4,,57415645",
982 NULL }
984 { &MEDIATYPE_Stream,
985 &MEDIASUBTYPE_AU,
986 { "0,4,,2e736e64",
987 NULL }
989 { &MEDIATYPE_Stream,
990 &MEDIASUBTYPE_AIFF,
991 { "0,4,,464f524d,8,4,,41494646",
992 "0,4,,464f524d,8,4,,41494643",
993 NULL }
995 { &MEDIATYPE_Stream,
996 &MEDIATYPE_Text,
997 { "0,4,,4C595249",
998 "0,4,,6C797269",
999 NULL }
1001 { &MEDIATYPE_Stream,
1002 &MEDIATYPE_Midi,
1003 { "0,4,,52494646,8,4,,524D4944",
1004 "0,4,,4D546864",
1005 NULL }
1007 { NULL } /* list terminator */
1010 /***********************************************************************
1011 * mediatype list
1014 static struct regsvr_mediatype_extension const mediatype_extension_list[] = {
1015 { &MEDIATYPE_Stream,
1016 &MEDIASUBTYPE_MPEG1Audio,
1017 ".mp3"
1019 { NULL } /* list terminator */
1022 /***********************************************************************
1023 * filter list
1026 static struct regsvr_filter const filter_list[] = {
1027 { &CLSID_AviSplitter,
1028 &CLSID_LegacyAmFilterCategory,
1029 {'A','V','I',' ','S','p','l','i','t','t','e','r',0},
1030 0x600000,
1031 { { 0,
1032 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_Avi },
1033 { NULL }
1036 { REG_PINFLAG_B_OUTPUT,
1037 { { &MEDIATYPE_Video, &GUID_NULL },
1038 { NULL }
1041 { 0xFFFFFFFF },
1044 { &CLSID_VideoRenderer,
1045 &CLSID_LegacyAmFilterCategory,
1046 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
1047 0x800000,
1048 { { REG_PINFLAG_B_RENDERER,
1049 { { &MEDIATYPE_Video, &GUID_NULL },
1050 { NULL }
1053 { 0xFFFFFFFF },
1056 { &CLSID_AVIDec,
1057 &CLSID_LegacyAmFilterCategory,
1058 {'A','V','I',' ','D','e','c','o','m','p','r','e','s','s','o','r',0},
1059 0x600000,
1060 { { 0,
1061 { { &MEDIATYPE_Video, &GUID_NULL },
1062 { NULL }
1065 { REG_PINFLAG_B_OUTPUT,
1066 { { &MEDIATYPE_Video, &GUID_NULL },
1067 { NULL }
1070 { 0xFFFFFFFF },
1073 { &CLSID_AsyncReader,
1074 &CLSID_LegacyAmFilterCategory,
1075 {'F','i','l','e',' ','S','o','u','r','c','e',' ','(','A','s','y','n','c','.',')',0},
1076 0x400000,
1077 { { REG_PINFLAG_B_OUTPUT,
1078 { { &MEDIATYPE_Stream, &GUID_NULL },
1079 { NULL }
1082 { 0xFFFFFFFF },
1085 { &CLSID_ACMWrapper,
1086 &CLSID_LegacyAmFilterCategory,
1087 {'A','C','M',' ','W','r','a','p','p','e','r',0},
1088 0x600000,
1089 { { 0,
1090 { { &MEDIATYPE_Audio, &GUID_NULL },
1091 { NULL }
1094 { REG_PINFLAG_B_OUTPUT,
1095 { { &MEDIATYPE_Audio, &GUID_NULL },
1096 { NULL }
1099 { 0xFFFFFFFF },
1102 { &CLSID_WAVEParser,
1103 &CLSID_LegacyAmFilterCategory,
1104 {'W','a','v','e',' ','P','a','r','s','e','r',0},
1105 0x400000,
1106 { { 0,
1107 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE },
1108 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AU },
1109 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AIFF },
1110 { NULL }
1113 { REG_PINFLAG_B_OUTPUT,
1114 { { &MEDIATYPE_Audio, &GUID_NULL },
1115 { NULL }
1118 { 0xFFFFFFFF },
1121 { NULL } /* list terminator */
1124 /***********************************************************************
1125 * DllRegisterServer (QUARTZ.@)
1127 HRESULT WINAPI DllRegisterServer(void)
1129 HRESULT hr;
1131 TRACE("\n");
1133 hr = register_coclasses(coclass_list);
1134 if (SUCCEEDED(hr))
1135 hr = register_interfaces(interface_list);
1136 if (SUCCEEDED(hr))
1137 hr = register_mediatypes_parsing(mediatype_parsing_list);
1138 if (SUCCEEDED(hr))
1139 hr = register_mediatypes_extension(mediatype_extension_list);
1140 if (SUCCEEDED(hr))
1141 hr = register_filters(filter_list);
1142 return hr;
1145 /***********************************************************************
1146 * DllUnregisterServer (QUARTZ.@)
1148 HRESULT WINAPI DllUnregisterServer(void)
1150 HRESULT hr;
1152 TRACE("\n");
1154 hr = unregister_filters(filter_list);
1155 if (SUCCEEDED(hr))
1156 hr = unregister_coclasses(coclass_list);
1157 if (SUCCEEDED(hr))
1158 hr = unregister_interfaces(interface_list);
1159 if (SUCCEEDED(hr))
1160 hr = unregister_mediatypes_parsing(mediatype_parsing_list);
1161 if (SUCCEEDED(hr))
1162 hr = unregister_mediatypes_extension(mediatype_extension_list);
1163 return hr;