686257daa8781c8e70cb747f49eb81a7b5481261
[reactos.git] / reactos / dll / directx / wine / quartz / regsvr.c
1 /*
2 * self-registerable dll functions for quartz.dll
3 *
4 * Copyright (C) 2003 John K. Hohm
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "quartz_private.h"
22
23 /*
24 * Near the bottom of this file are the exported DllRegisterServer and
25 * DllUnregisterServer, which make all this worthwhile.
26 */
27
28 /***********************************************************************
29 * interface for self-registering
30 */
31 struct regsvr_interface
32 {
33 IID const *iid; /* NULL for end of list */
34 LPCSTR name; /* can be NULL to omit */
35 IID const *base_iid; /* can be NULL to omit */
36 int num_methods; /* can be <0 to omit */
37 CLSID const *ps_clsid; /* can be NULL to omit */
38 CLSID const *ps_clsid32; /* can be NULL to omit */
39 };
40
41 static HRESULT register_interfaces(struct regsvr_interface const *list);
42 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
43
44 struct regsvr_coclass
45 {
46 CLSID const *clsid; /* NULL for end of list */
47 LPCSTR name; /* can be NULL to omit */
48 LPCSTR ips; /* can be NULL to omit */
49 LPCSTR ips32; /* can be NULL to omit */
50 LPCSTR ips32_tmodel; /* can be NULL to omit */
51 LPCSTR progid; /* can be NULL to omit */
52 LPCSTR viprogid; /* can be NULL to omit */
53 LPCSTR progid_extra; /* can be NULL to omit */
54 };
55
56 static HRESULT register_coclasses(struct regsvr_coclass const *list);
57 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
58
59 struct regsvr_mediatype_parsing
60 {
61 CLSID const *majortype; /* NULL for end of list */
62 CLSID const *subtype;
63 LPCSTR line[11]; /* NULL for end of list */
64 };
65
66 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
67 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
68
69 struct regsvr_mediatype_extension
70 {
71 CLSID const *majortype; /* NULL for end of list */
72 CLSID const *subtype;
73 LPCSTR extension;
74 };
75
76 struct mediatype
77 {
78 CLSID const *majortype; /* NULL for end of list */
79 CLSID const *subtype;
80 DWORD fourcc;
81 };
82
83 struct pin
84 {
85 DWORD flags; /* 0xFFFFFFFF for end of list */
86 struct mediatype mediatypes[11];
87 };
88
89 struct regsvr_filter
90 {
91 CLSID const *clsid; /* NULL for end of list */
92 CLSID const *category;
93 WCHAR name[50];
94 DWORD merit;
95 struct pin pins[11];
96 };
97
98 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list);
99 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list);
100
101 static HRESULT register_filters(struct regsvr_filter const *list);
102 static HRESULT unregister_filters(struct regsvr_filter const *list);
103
104 /***********************************************************************
105 * static string constants
106 */
107 static const WCHAR interface_keyname[] = {
108 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
109 static const WCHAR base_ifa_keyname[] = {
110 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
111 'e', 0 };
112 static const WCHAR num_methods_keyname[] = {
113 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
114 static const WCHAR ps_clsid_keyname[] = {
115 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
116 'i', 'd', 0 };
117 static const WCHAR ps_clsid32_keyname[] = {
118 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
119 'i', 'd', '3', '2', 0 };
120 static const WCHAR clsid_keyname[] = {
121 'C', 'L', 'S', 'I', 'D', 0 };
122 static const WCHAR curver_keyname[] = {
123 'C', 'u', 'r', 'V', 'e', 'r', 0 };
124 static const WCHAR ips_keyname[] = {
125 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
126 0 };
127 static const WCHAR ips32_keyname[] = {
128 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
129 '3', '2', 0 };
130 static const WCHAR progid_keyname[] = {
131 'P', 'r', 'o', 'g', 'I', 'D', 0 };
132 static const WCHAR viprogid_keyname[] = {
133 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
134 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
135 0 };
136 static const char tmodel_valuename[] = "ThreadingModel";
137 static const WCHAR mediatype_name[] = {
138 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
139 static const WCHAR subtype_valuename[] = {
140 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
141 static const WCHAR sourcefilter_valuename[] = {
142 'S', 'o', 'u', 'r', 'c', 'e', ' ', 'F', 'i', 'l', 't', 'e', 'r', 0 };
143 static const WCHAR extensions_keyname[] = {
144 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', 0 };
145
146 /***********************************************************************
147 * static helper functions
148 */
149 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
150 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
151 WCHAR const *value);
152 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
153 char const *value);
154 static LONG register_progid(WCHAR const *clsid,
155 char const *progid, char const *curver_progid,
156 char const *name, char const *extra);
157
158 /***********************************************************************
159 * register_interfaces
160 */
161 static HRESULT register_interfaces(struct regsvr_interface const *list)
162 {
163 LONG res = ERROR_SUCCESS;
164 HKEY interface_key;
165
166 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
167 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
168 if (res != ERROR_SUCCESS) goto error_return;
169
170 for (; res == ERROR_SUCCESS && list->iid; ++list) {
171 WCHAR buf[39];
172 HKEY iid_key;
173
174 StringFromGUID2(list->iid, buf, 39);
175 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
176 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
177 if (res != ERROR_SUCCESS) goto error_close_interface_key;
178
179 if (list->name) {
180 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ, (const BYTE*)list->name,
181 strlen(list->name) + 1);
182 if (res != ERROR_SUCCESS) goto error_close_iid_key;
183 }
184
185 if (list->base_iid) {
186 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
187 if (res != ERROR_SUCCESS) goto error_close_iid_key;
188 }
189
190 if (0 <= list->num_methods) {
191 static const WCHAR fmt[] = { '%', 'd', 0 };
192 HKEY key;
193
194 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
195 KEY_READ | KEY_WRITE, NULL, &key, NULL);
196 if (res != ERROR_SUCCESS) goto error_close_iid_key;
197
198 sprintfW(buf, fmt, list->num_methods);
199 res = RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE*)buf,
200 (lstrlenW(buf) + 1) * sizeof(WCHAR));
201 RegCloseKey(key);
202
203 if (res != ERROR_SUCCESS) goto error_close_iid_key;
204 }
205
206 if (list->ps_clsid) {
207 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
208 if (res != ERROR_SUCCESS) goto error_close_iid_key;
209 }
210
211 if (list->ps_clsid32) {
212 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
213 if (res != ERROR_SUCCESS) goto error_close_iid_key;
214 }
215
216 error_close_iid_key:
217 RegCloseKey(iid_key);
218 }
219
220 error_close_interface_key:
221 RegCloseKey(interface_key);
222 error_return:
223 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
224 }
225
226 /***********************************************************************
227 * unregister_interfaces
228 */
229 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
230 {
231 LONG res = ERROR_SUCCESS;
232 HKEY interface_key;
233
234 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
235 KEY_READ | KEY_WRITE, &interface_key);
236 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
237 if (res != ERROR_SUCCESS) goto error_return;
238
239 for (; res == ERROR_SUCCESS && list->iid; ++list) {
240 WCHAR buf[39];
241
242 StringFromGUID2(list->iid, buf, 39);
243 res = SHDeleteKeyW(interface_key, buf);
244 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
245 }
246
247 RegCloseKey(interface_key);
248 error_return:
249 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
250 }
251
252 /***********************************************************************
253 * register_coclasses
254 */
255 static HRESULT register_coclasses(struct regsvr_coclass const *list)
256 {
257 LONG res = ERROR_SUCCESS;
258 HKEY coclass_key;
259
260 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
261 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
262 if (res != ERROR_SUCCESS) goto error_return;
263
264 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
265 WCHAR buf[39];
266 HKEY clsid_key;
267
268 StringFromGUID2(list->clsid, buf, 39);
269 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
270 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
271 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
272
273 if (list->name) {
274 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, (const BYTE*)list->name,
275 strlen(list->name) + 1);
276 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
277 }
278
279 if (list->ips) {
280 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
281 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
282 }
283
284 if (list->ips32) {
285 HKEY ips32_key;
286
287 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
288 KEY_READ | KEY_WRITE, NULL,
289 &ips32_key, NULL);
290 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
291
292 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, (const BYTE*)list->ips32,
293 lstrlenA(list->ips32) + 1);
294 if (res == ERROR_SUCCESS && list->ips32_tmodel)
295 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
296 (const BYTE*)list->ips32_tmodel,
297 strlen(list->ips32_tmodel) + 1);
298 RegCloseKey(ips32_key);
299 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
300 }
301
302 if (list->progid) {
303 res = register_key_defvalueA(clsid_key, progid_keyname,
304 list->progid);
305 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
306
307 res = register_progid(buf, list->progid, NULL,
308 list->name, list->progid_extra);
309 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
310 }
311
312 if (list->viprogid) {
313 res = register_key_defvalueA(clsid_key, viprogid_keyname,
314 list->viprogid);
315 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
316
317 res = register_progid(buf, list->viprogid, list->progid,
318 list->name, list->progid_extra);
319 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
320 }
321
322 error_close_clsid_key:
323 RegCloseKey(clsid_key);
324 }
325
326 error_close_coclass_key:
327 RegCloseKey(coclass_key);
328 error_return:
329 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
330 }
331
332 /***********************************************************************
333 * unregister_coclasses
334 */
335 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
336 {
337 LONG res = ERROR_SUCCESS;
338 HKEY coclass_key;
339
340 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
341 KEY_READ | KEY_WRITE, &coclass_key);
342 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
343 if (res != ERROR_SUCCESS) goto error_return;
344
345 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
346 WCHAR buf[39];
347
348 StringFromGUID2(list->clsid, buf, 39);
349 res = SHDeleteKeyW(coclass_key, buf);
350 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
351 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
352
353 if (list->progid) {
354 res = SHDeleteKeyA(HKEY_CLASSES_ROOT, list->progid);
355 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
356 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
357 }
358
359 if (list->viprogid) {
360 res = SHDeleteKeyA(HKEY_CLASSES_ROOT, list->viprogid);
361 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
362 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
363 }
364 }
365
366 error_close_coclass_key:
367 RegCloseKey(coclass_key);
368 error_return:
369 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
370 }
371
372 /***********************************************************************
373 * register_mediatypes_parsing
374 */
375 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
376 {
377 LONG res = ERROR_SUCCESS;
378 HKEY mediatype_key;
379 WCHAR buf[39];
380 int i;
381
382 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
383 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
384 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
385
386 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
387 HKEY majortype_key = NULL;
388 HKEY subtype_key = NULL;
389
390 StringFromGUID2(list->majortype, buf, 39);
391 res = RegCreateKeyExW(mediatype_key, buf, 0, NULL, 0,
392 KEY_READ | KEY_WRITE, NULL, &majortype_key, NULL);
393 if (res != ERROR_SUCCESS) goto error_close_keys;
394
395 StringFromGUID2(list->subtype, buf, 39);
396 res = RegCreateKeyExW(majortype_key, buf, 0, NULL, 0,
397 KEY_READ | KEY_WRITE, NULL, &subtype_key, NULL);
398 if (res != ERROR_SUCCESS) goto error_close_keys;
399
400 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
401 res = RegSetValueExW(subtype_key, sourcefilter_valuename, 0, REG_SZ, (const BYTE*)buf,
402 (lstrlenW(buf) + 1) * sizeof(WCHAR));
403 if (res != ERROR_SUCCESS) goto error_close_keys;
404
405 for(i = 0; list->line[i]; i++) {
406 char buffer[3];
407 wsprintfA(buffer, "%d", i);
408 res = RegSetValueExA(subtype_key, buffer, 0, REG_SZ, (const BYTE*)list->line[i],
409 lstrlenA(list->line[i]));
410 if (res != ERROR_SUCCESS) goto error_close_keys;
411 }
412
413 error_close_keys:
414 if (majortype_key)
415 RegCloseKey(majortype_key);
416 if (subtype_key)
417 RegCloseKey(subtype_key);
418 }
419
420 RegCloseKey(mediatype_key);
421
422 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
423 }
424
425 /***********************************************************************
426 * register_mediatypes_extension
427 */
428 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list)
429 {
430 LONG res = ERROR_SUCCESS;
431 HKEY mediatype_key;
432 HKEY extensions_root_key = NULL;
433 WCHAR buf[39];
434
435 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
436 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
437 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
438
439 res = RegCreateKeyExW(mediatype_key, extensions_keyname, 0, NULL, 0,
440 KEY_READ | KEY_WRITE, NULL, &extensions_root_key, NULL);
441 if (res != ERROR_SUCCESS) goto error_return;
442
443 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
444 HKEY extension_key;
445
446 res = RegCreateKeyExA(extensions_root_key, list->extension, 0, NULL, 0,
447 KEY_READ | KEY_WRITE, NULL, &extension_key, NULL);
448 if (res != ERROR_SUCCESS) break;
449
450 StringFromGUID2(list->majortype, buf, 39);
451 res = RegSetValueExW(extension_key, mediatype_name, 0, REG_SZ, (const BYTE*)buf,
452 (lstrlenW(buf) + 1) * sizeof(WCHAR));
453 if (res != ERROR_SUCCESS) goto error_close_key;
454
455 StringFromGUID2(list->subtype, buf, 39);
456 res = RegSetValueExW(extension_key, subtype_valuename, 0, REG_SZ, (const BYTE*)buf,
457 (lstrlenW(buf) + 1) * sizeof(WCHAR));
458 if (res != ERROR_SUCCESS) goto error_close_key;
459
460 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
461 res = RegSetValueExW(extension_key, sourcefilter_valuename, 0, REG_SZ, (const BYTE*)buf,
462 (lstrlenW(buf) + 1) * sizeof(WCHAR));
463 if (res != ERROR_SUCCESS) goto error_close_key;
464
465 error_close_key:
466 RegCloseKey(extension_key);
467 }
468
469 error_return:
470 RegCloseKey(mediatype_key);
471 if (extensions_root_key)
472 RegCloseKey(extensions_root_key);
473
474 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
475 }
476
477 /***********************************************************************
478 * unregister_mediatypes_parsing
479 */
480 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
481 {
482 LONG res;
483 HKEY mediatype_key;
484 HKEY majortype_key;
485 WCHAR buf[39];
486
487 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
488 KEY_READ | KEY_WRITE, &mediatype_key);
489 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
490 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
491
492 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
493 StringFromGUID2(list->majortype, buf, 39);
494 res = RegOpenKeyExW(mediatype_key, buf, 0,
495 KEY_READ | KEY_WRITE, &majortype_key);
496 if (res == ERROR_FILE_NOT_FOUND) {
497 res = ERROR_SUCCESS;
498 continue;
499 }
500 if (res != ERROR_SUCCESS) break;
501
502 StringFromGUID2(list->subtype, buf, 39);
503 res = SHDeleteKeyW(majortype_key, buf);
504 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
505
506 /* Removed majortype key if there is no more subtype key */
507 res = RegDeleteKeyW(majortype_key, 0);
508 if (res == ERROR_ACCESS_DENIED) res = ERROR_SUCCESS;
509
510 RegCloseKey(majortype_key);
511 }
512
513 RegCloseKey(mediatype_key);
514
515 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
516 }
517
518 /***********************************************************************
519 * unregister_mediatypes_extension
520 */
521 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list)
522 {
523 LONG res;
524 HKEY mediatype_key;
525 HKEY extensions_root_key = NULL;
526
527 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
528 KEY_READ | KEY_WRITE, &mediatype_key);
529 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
530 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
531
532 res = RegOpenKeyExW(mediatype_key, extensions_keyname, 0,
533 KEY_READ | KEY_WRITE, &extensions_root_key);
534 if (res == ERROR_FILE_NOT_FOUND)
535 res = ERROR_SUCCESS;
536 else if (res == ERROR_SUCCESS)
537 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
538 res = SHDeleteKeyA(extensions_root_key, list->extension);
539 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
540 }
541
542 RegCloseKey(mediatype_key);
543 if (extensions_root_key)
544 RegCloseKey(extensions_root_key);
545
546 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
547 }
548
549 /***********************************************************************
550 * register_filters
551 */
552 static HRESULT register_filters(struct regsvr_filter const *list)
553 {
554 HRESULT hr;
555 IFilterMapper2* pFM2 = NULL;
556
557 CoInitialize(NULL);
558 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
559
560 if (SUCCEEDED(hr)) {
561 for (; SUCCEEDED(hr) && list->clsid; ++list) {
562 REGFILTER2 rf2;
563 REGFILTERPINS2* prfp2;
564 int i;
565
566 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
567 rf2.dwVersion = 2;
568 rf2.dwMerit = list->merit;
569 rf2.u.s2.cPins2 = i;
570 rf2.u.s2.rgPins2 = prfp2 = CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
571 if (!prfp2) {
572 hr = E_OUTOFMEMORY;
573 break;
574 }
575 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
576 REGPINTYPES* lpMediatype;
577 CLSID* lpClsid;
578 int j, nbmt;
579
580 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
581 /* Allocate a single buffer for regpintypes struct and clsids */
582 lpMediatype = CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
583 if (!lpMediatype) {
584 hr = E_OUTOFMEMORY;
585 break;
586 }
587 lpClsid = (CLSID*) (lpMediatype + nbmt);
588 for (j = 0; j < nbmt; j++) {
589 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
590 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
591 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
592 if (list->pins[i].mediatypes[j].subtype)
593 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
594 else {
595 /* Subtype are often a combination of major type + fourcc/tag */
596 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
597 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
598 }
599 }
600 prfp2[i].dwFlags = list->pins[i].flags;
601 prfp2[i].cInstances = 0;
602 prfp2[i].nMediaTypes = j;
603 prfp2[i].lpMediaType = lpMediatype;
604 prfp2[i].nMediums = 0;
605 prfp2[i].lpMedium = NULL;
606 prfp2[i].clsPinCategory = NULL;
607 }
608
609 if (FAILED(hr)) {
610 ERR("failed to register with hresult 0x%x\n", hr);
611 CoTaskMemFree(prfp2);
612 break;
613 }
614
615 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
616
617 while (i) {
618 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
619 i--;
620 }
621 CoTaskMemFree(prfp2);
622 }
623 }
624
625 if (pFM2)
626 IFilterMapper2_Release(pFM2);
627
628 CoUninitialize();
629
630 return hr;
631 }
632
633 /***********************************************************************
634 * unregister_filters
635 */
636 static HRESULT unregister_filters(struct regsvr_filter const *list)
637 {
638 HRESULT hr;
639 IFilterMapper2* pFM2;
640
641 CoInitialize(NULL);
642
643 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
644
645 if (SUCCEEDED(hr)) {
646 for (; SUCCEEDED(hr) && list->clsid; ++list)
647 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
648 IFilterMapper2_Release(pFM2);
649 }
650
651 CoUninitialize();
652
653 return hr;
654 }
655
656 /***********************************************************************
657 * regsvr_key_guid
658 */
659 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
660 {
661 WCHAR buf[39];
662
663 StringFromGUID2(guid, buf, 39);
664 return register_key_defvalueW(base, name, buf);
665 }
666
667 /***********************************************************************
668 * regsvr_key_defvalueW
669 */
670 static LONG register_key_defvalueW(
671 HKEY base,
672 WCHAR const *name,
673 WCHAR const *value)
674 {
675 LONG res;
676 HKEY key;
677
678 res = RegCreateKeyExW(base, name, 0, NULL, 0,
679 KEY_READ | KEY_WRITE, NULL, &key, NULL);
680 if (res != ERROR_SUCCESS) return res;
681 res = RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE*)value,
682 (lstrlenW(value) + 1) * sizeof(WCHAR));
683 RegCloseKey(key);
684 return res;
685 }
686
687 /***********************************************************************
688 * regsvr_key_defvalueA
689 */
690 static LONG register_key_defvalueA(
691 HKEY base,
692 WCHAR const *name,
693 char const *value)
694 {
695 LONG res;
696 HKEY key;
697
698 res = RegCreateKeyExW(base, name, 0, NULL, 0,
699 KEY_READ | KEY_WRITE, NULL, &key, NULL);
700 if (res != ERROR_SUCCESS) return res;
701 res = RegSetValueExA(key, NULL, 0, REG_SZ, (const BYTE*)value, lstrlenA(value) + 1);
702 RegCloseKey(key);
703 return res;
704 }
705
706 /***********************************************************************
707 * regsvr_progid
708 */
709 static LONG register_progid(
710 WCHAR const *clsid,
711 char const *progid,
712 char const *curver_progid,
713 char const *name,
714 char const *extra)
715 {
716 LONG res;
717 HKEY progid_key;
718
719 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
720 NULL, 0, KEY_READ | KEY_WRITE, NULL,
721 &progid_key, NULL);
722 if (res != ERROR_SUCCESS) return res;
723
724 if (name) {
725 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ, (const BYTE*)name, strlen(name) + 1);
726 if (res != ERROR_SUCCESS) goto error_close_progid_key;
727 }
728
729 if (clsid) {
730 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
731 if (res != ERROR_SUCCESS) goto error_close_progid_key;
732 }
733
734 if (curver_progid) {
735 res = register_key_defvalueA(progid_key, curver_keyname,
736 curver_progid);
737 if (res != ERROR_SUCCESS) goto error_close_progid_key;
738 }
739
740 if (extra) {
741 HKEY extra_key;
742
743 res = RegCreateKeyExA(progid_key, extra, 0,
744 NULL, 0, KEY_READ | KEY_WRITE, NULL,
745 &extra_key, NULL);
746 if (res == ERROR_SUCCESS)
747 RegCloseKey(extra_key);
748 }
749
750 error_close_progid_key:
751 RegCloseKey(progid_key);
752 return res;
753 }
754
755 /***********************************************************************
756 * coclass list
757 */
758 static struct regsvr_coclass const coclass_list[] = {
759 { NULL } /* list terminator */
760 };
761
762 /***********************************************************************
763 * interface list
764 */
765
766 static struct regsvr_interface const interface_list[] = {
767 { NULL } /* list terminator */
768 };
769
770 /***********************************************************************
771 * mediatype list
772 */
773
774 static struct regsvr_mediatype_parsing const mediatype_parsing_list[] = {
775 { &MEDIATYPE_Stream,
776 &MEDIASUBTYPE_Avi,
777 { "0,4,,52494646,8,4,,41564920",
778 NULL }
779 },
780 { &MEDIATYPE_Stream,
781 &MEDIASUBTYPE_MPEG1System,
782 { "0, 16, FFFFFFFFF100010001800001FFFFFFFF, 000001BA2100010001800001000001BB",
783 NULL }
784 },
785 { &MEDIATYPE_Stream,
786 &MEDIASUBTYPE_MPEG1VideoCD,
787 { "0, 4, , 52494646, 8, 8, , 43445841666D7420, 36, 20, FFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF, 646174610000000000FFFFFFFFFFFFFFFFFFFF00",
788 NULL }
789 },
790 { &MEDIATYPE_Stream,
791 &MEDIASUBTYPE_MPEG1Video,
792 { "0, 4, , 000001B3",
793 NULL }
794 },
795 { &MEDIATYPE_Stream,
796 &MEDIASUBTYPE_MPEG1Audio,
797 { "0, 2, FFE0, FFE0",
798 "0, 10, FFFFFF00000080808080, 494433000000000000",
799 NULL }
800 },
801 { &MEDIATYPE_Stream,
802 &MEDIASUBTYPE_QTMovie,
803 { "4, 4, , 6d646174",
804 "4, 4, , 6d6f6f76",
805 NULL }
806 },
807 { &MEDIATYPE_Stream,
808 &MEDIASUBTYPE_WAVE,
809 { "0,4,,52494646,8,4,,57415645",
810 NULL }
811 },
812 { &MEDIATYPE_Stream,
813 &MEDIASUBTYPE_AU,
814 { "0,4,,2e736e64",
815 NULL }
816 },
817 { &MEDIATYPE_Stream,
818 &MEDIASUBTYPE_AIFF,
819 { "0,4,,464f524d,8,4,,41494646",
820 "0,4,,464f524d,8,4,,41494643",
821 NULL }
822 },
823 { &MEDIATYPE_Stream,
824 &MEDIATYPE_Text,
825 { "0,4,,4C595249",
826 "0,4,,6C797269",
827 NULL }
828 },
829 { &MEDIATYPE_Stream,
830 &MEDIATYPE_Midi,
831 { "0,4,,52494646,8,4,,524D4944",
832 "0,4,,4D546864",
833 NULL }
834 },
835 { NULL } /* list terminator */
836 };
837
838 /***********************************************************************
839 * mediatype list
840 */
841
842 static struct regsvr_mediatype_extension const mediatype_extension_list[] = {
843 { &MEDIATYPE_Stream,
844 &MEDIASUBTYPE_MPEG1Audio,
845 ".mp3"
846 },
847 { NULL } /* list terminator */
848 };
849
850 /***********************************************************************
851 * filter list
852 */
853
854 static struct regsvr_filter const filter_list[] = {
855 { &CLSID_AviSplitter,
856 &CLSID_LegacyAmFilterCategory,
857 {'A','V','I',' ','S','p','l','i','t','t','e','r',0},
858 0x5ffff0,
859 { { 0,
860 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_Avi },
861 { NULL }
862 },
863 },
864 { REG_PINFLAG_B_OUTPUT,
865 { { &MEDIATYPE_Video, &GUID_NULL },
866 { NULL }
867 },
868 },
869 { 0xFFFFFFFF },
870 }
871 },
872 { &CLSID_MPEG1Splitter,
873 &CLSID_LegacyAmFilterCategory,
874 {'M','P','E','G','-','I',' ','S','t','r','e','a','m',' ','S','p','l','i','t','t','e','r',0},
875 0x5ffff0,
876 { { 0,
877 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Audio },
878 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Video },
879 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1System },
880 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1VideoCD },
881 { NULL }
882 },
883 },
884 { REG_PINFLAG_B_OUTPUT,
885 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1Packet },
886 { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1AudioPayload },
887 { NULL }
888 },
889 },
890 { REG_PINFLAG_B_OUTPUT,
891 { { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Packet },
892 { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Payload },
893 { NULL }
894 },
895 },
896 { 0xFFFFFFFF },
897 }
898 },
899 { &CLSID_NullRenderer,
900 &CLSID_LegacyAmFilterCategory,
901 {'N','u','l','l',' ','R','e','n','d','e','r','e','r',0},
902 0x200000,
903 { { REG_PINFLAG_B_RENDERER,
904 { { &MEDIATYPE_NULL, &GUID_NULL },
905 { NULL }
906 },
907 },
908 { 0xFFFFFFFF },
909 }
910 },
911 { &CLSID_VideoRenderer,
912 &CLSID_LegacyAmFilterCategory,
913 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
914 0x800000,
915 { { REG_PINFLAG_B_RENDERER,
916 { { &MEDIATYPE_Video, &GUID_NULL },
917 { NULL }
918 },
919 },
920 { 0xFFFFFFFF },
921 }
922 },
923 { &CLSID_VideoRendererDefault,
924 &CLSID_LegacyAmFilterCategory,
925 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
926 0x800000,
927 { { REG_PINFLAG_B_RENDERER,
928 { { &MEDIATYPE_Video, &GUID_NULL },
929 { NULL }
930 },
931 },
932 { 0xFFFFFFFF },
933 }
934 },
935 { &CLSID_VideoMixingRenderer,
936 &CLSID_LegacyAmFilterCategory,
937 {'V','i','d','e','o',' ','M','i','x','i','n','g',' ','R','e','n','d','e','r','e','r',0},
938 0x200000,
939 { { REG_PINFLAG_B_RENDERER,
940 { { &MEDIATYPE_Video, &GUID_NULL },
941 { NULL }
942 },
943 },
944 { 0xFFFFFFFF },
945 }
946 },
947 { &CLSID_VideoMixingRenderer9,
948 &CLSID_LegacyAmFilterCategory,
949 {'V','i','d','e','o',' ','M','i','x','i','n','g',' ','R','e','n','d','e','r','e','r',' ','9',0},
950 0x200000,
951 { { REG_PINFLAG_B_RENDERER,
952 { { &MEDIATYPE_Video, &GUID_NULL },
953 { NULL }
954 },
955 },
956 { 0xFFFFFFFF },
957 }
958 },
959 { &CLSID_DSoundRender,
960 &CLSID_LegacyAmFilterCategory,
961 {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r',0},
962 0x800000,
963 { { REG_PINFLAG_B_RENDERER,
964 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_PCM },
965 /* { &MEDIATYPE_Audio, &MEDIASUBTYPE_IEEE_FLOAT }, */
966 { NULL }
967 },
968 },
969 { 0xFFFFFFFF },
970 }
971 },
972 { &CLSID_AudioRender,
973 &CLSID_LegacyAmFilterCategory,
974 {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r',0},
975 0x800000,
976 { { REG_PINFLAG_B_RENDERER,
977 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_PCM },
978 /* { &MEDIATYPE_Audio, &MEDIASUBTYPE_IEEE_FLOAT }, */
979 { NULL }
980 },
981 },
982 { 0xFFFFFFFF },
983 }
984 },
985 { &CLSID_AVIDec,
986 &CLSID_LegacyAmFilterCategory,
987 {'A','V','I',' ','D','e','c','o','m','p','r','e','s','s','o','r',0},
988 0x5ffff0,
989 { { 0,
990 { { &MEDIATYPE_Video, &GUID_NULL },
991 { NULL }
992 },
993 },
994 { REG_PINFLAG_B_OUTPUT,
995 { { &MEDIATYPE_Video, &GUID_NULL },
996 { NULL }
997 },
998 },
999 { 0xFFFFFFFF },
1000 }
1001 },
1002 { &CLSID_AsyncReader,
1003 &CLSID_LegacyAmFilterCategory,
1004 {'F','i','l','e',' ','S','o','u','r','c','e',' ','(','A','s','y','n','c','.',')',0},
1005 0x400000,
1006 { { REG_PINFLAG_B_OUTPUT,
1007 { { &MEDIATYPE_Stream, &GUID_NULL },
1008 { NULL }
1009 },
1010 },
1011 { 0xFFFFFFFF },
1012 }
1013 },
1014 { &CLSID_ACMWrapper,
1015 &CLSID_LegacyAmFilterCategory,
1016 {'A','C','M',' ','W','r','a','p','p','e','r',0},
1017 0x5ffff0,
1018 { { 0,
1019 { { &MEDIATYPE_Audio, &GUID_NULL },
1020 { NULL }
1021 },
1022 },
1023 { REG_PINFLAG_B_OUTPUT,
1024 { { &MEDIATYPE_Audio, &GUID_NULL },
1025 { NULL }
1026 },
1027 },
1028 { 0xFFFFFFFF },
1029 }
1030 },
1031 { &CLSID_WAVEParser,
1032 &CLSID_LegacyAmFilterCategory,
1033 {'W','a','v','e',' ','P','a','r','s','e','r',0},
1034 0x400000,
1035 { { 0,
1036 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE },
1037 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AU },
1038 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AIFF },
1039 { NULL }
1040 },
1041 },
1042 { REG_PINFLAG_B_OUTPUT,
1043 { { &MEDIATYPE_Audio, &GUID_NULL },
1044 { NULL }
1045 },
1046 },
1047 { 0xFFFFFFFF },
1048 }
1049 },
1050 { NULL } /* list terminator */
1051 };
1052
1053 extern HRESULT WINAPI QUARTZ_DllRegisterServer(void) DECLSPEC_HIDDEN;
1054 extern HRESULT WINAPI QUARTZ_DllUnregisterServer(void) DECLSPEC_HIDDEN;
1055
1056 /***********************************************************************
1057 * DllRegisterServer (QUARTZ.@)
1058 */
1059 HRESULT WINAPI DllRegisterServer(void)
1060 {
1061 HRESULT hr;
1062
1063 TRACE("\n");
1064
1065 hr = QUARTZ_DllRegisterServer();
1066 if (SUCCEEDED(hr))
1067 hr = register_coclasses(coclass_list);
1068 if (SUCCEEDED(hr))
1069 hr = register_interfaces(interface_list);
1070 if (SUCCEEDED(hr))
1071 hr = register_mediatypes_parsing(mediatype_parsing_list);
1072 if (SUCCEEDED(hr))
1073 hr = register_mediatypes_extension(mediatype_extension_list);
1074 if (SUCCEEDED(hr))
1075 hr = register_filters(filter_list);
1076 return hr;
1077 }
1078
1079 /***********************************************************************
1080 * DllUnregisterServer (QUARTZ.@)
1081 */
1082 HRESULT WINAPI DllUnregisterServer(void)
1083 {
1084 HRESULT hr;
1085
1086 TRACE("\n");
1087
1088 hr = unregister_filters(filter_list);
1089 if (SUCCEEDED(hr))
1090 hr = unregister_coclasses(coclass_list);
1091 if (SUCCEEDED(hr))
1092 hr = unregister_interfaces(interface_list);
1093 if (SUCCEEDED(hr))
1094 hr = unregister_mediatypes_parsing(mediatype_parsing_list);
1095 if (SUCCEEDED(hr))
1096 hr = unregister_mediatypes_extension(mediatype_extension_list);
1097 if (SUCCEEDED(hr))
1098 hr = QUARTZ_DllUnregisterServer();
1099 return hr;
1100 }