winefile: Add a Portuguese translation (contributed by Americo Jose Melo).
[wine/hacks.git] / dlls / msxml3 / regsvr.c
blob3686590c3a9a7ae782a02901b5895cfe669db000
1 /*
2 * MSXML3 self-registerable dll functions
4 * Copyright (C) 2003 John K. Hohm
5 * Copyright (C) 2006 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "winerror.h"
30 #include "ole2.h"
31 #include "msxml.h"
32 #include "xmldom.h"
33 #include "xmldso.h"
34 #include "msxml2.h"
36 /* undef the #define in msxml2 so that we can access the v.2 version
37 independent CLSID as well as the v.3 one. */
38 #undef CLSID_DOMDocument
40 #include "msxml_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ole);
47 * Near the bottom of this file are the exported DllRegisterServer and
48 * DllUnregisterServer, which make all this worthwhile.
51 /***********************************************************************
52 * interface for self-registering
54 struct regsvr_interface
56 IID const *iid; /* NULL for end of list */
57 LPCSTR name; /* can be NULL to omit */
58 IID const *base_iid; /* can be NULL to omit */
59 int num_methods; /* can be <0 to omit */
60 CLSID const *ps_clsid; /* can be NULL to omit */
61 CLSID const *ps_clsid32; /* can be NULL to omit */
64 static HRESULT register_interfaces(struct regsvr_interface const *list);
65 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
67 struct regsvr_coclass
69 CLSID const *clsid; /* NULL for end of list */
70 LPCSTR name; /* can be NULL to omit */
71 LPCSTR ips; /* can be NULL to omit */
72 LPCSTR ips32; /* can be NULL to omit */
73 LPCSTR ips32_tmodel; /* can be NULL to omit */
74 LPCSTR progid; /* can be NULL to omit */
75 LPCSTR version; /* can be NULL to omit */
78 static HRESULT register_coclasses(struct regsvr_coclass const *list);
79 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
81 struct progid
83 LPCSTR name; /* NULL for end of list */
84 LPCSTR description; /* can be NULL to omit */
85 CLSID const *clsid;
86 LPCSTR curver; /* can be NULL to omit */
89 static HRESULT register_progids(struct progid const *list);
90 static HRESULT unregister_progids(struct progid const *list);
92 /***********************************************************************
93 * static string constants
95 static WCHAR const interface_keyname[10] = {
96 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
97 static WCHAR const base_ifa_keyname[14] = {
98 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
99 'e', 0 };
100 static WCHAR const num_methods_keyname[11] = {
101 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
102 static WCHAR const ps_clsid_keyname[15] = {
103 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
104 'i', 'd', 0 };
105 static WCHAR const ps_clsid32_keyname[17] = {
106 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
107 'i', 'd', '3', '2', 0 };
108 static WCHAR const clsid_keyname[6] = {
109 'C', 'L', 'S', 'I', 'D', 0 };
110 static WCHAR const ips_keyname[13] = {
111 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
112 0 };
113 static WCHAR const ips32_keyname[15] = {
114 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
115 '3', '2', 0 };
116 static WCHAR const progid_keyname[7] = {
117 'P', 'r', 'o', 'g', 'I', 'D', 0 };
118 static WCHAR const versionindependentprogid_keyname[] = {
119 'V', 'e', 'r', 's', 'i', 'o', 'n',
120 'I', 'n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 't',
121 'P', 'r', 'o', 'g', 'I', 'D', 0 };
122 static WCHAR const version_keyname[] = {
123 'V', 'e', 'r', 's', 'i', 'o', 'n', 0 };
124 static WCHAR const curver_keyname[] = {
125 'C', 'u', 'r', 'V', 'e', 'r', 0 };
126 static char const tmodel_valuename[] = "ThreadingModel";
128 /***********************************************************************
129 * static helper functions
131 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
132 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
133 WCHAR const *value);
134 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
135 char const *value);
136 static LONG recursive_delete_key(HKEY key);
137 static LONG recursive_delete_keyA(HKEY base, char const *name);
138 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name);
140 /***********************************************************************
141 * register_interfaces
143 static HRESULT register_interfaces(struct regsvr_interface const *list)
145 LONG res = ERROR_SUCCESS;
146 HKEY interface_key;
148 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
149 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
150 if (res != ERROR_SUCCESS) goto error_return;
152 for (; res == ERROR_SUCCESS && list->iid; ++list) {
153 WCHAR buf[39];
154 HKEY iid_key;
156 StringFromGUID2(list->iid, buf, 39);
157 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
158 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
159 if (res != ERROR_SUCCESS) goto error_close_interface_key;
161 if (list->name) {
162 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
163 (CONST BYTE*)(list->name),
164 strlen(list->name) + 1);
165 if (res != ERROR_SUCCESS) goto error_close_iid_key;
168 if (list->base_iid) {
169 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
170 if (res != ERROR_SUCCESS) goto error_close_iid_key;
173 if (0 <= list->num_methods) {
174 static WCHAR const fmt[3] = { '%', 'd', 0 };
175 HKEY key;
177 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
178 KEY_READ | KEY_WRITE, NULL, &key, NULL);
179 if (res != ERROR_SUCCESS) goto error_close_iid_key;
181 wsprintfW(buf, fmt, list->num_methods);
182 res = RegSetValueExW(key, NULL, 0, REG_SZ,
183 (CONST BYTE*)buf,
184 (lstrlenW(buf) + 1) * sizeof(WCHAR));
185 RegCloseKey(key);
187 if (res != ERROR_SUCCESS) goto error_close_iid_key;
190 if (list->ps_clsid) {
191 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
192 if (res != ERROR_SUCCESS) goto error_close_iid_key;
195 if (list->ps_clsid32) {
196 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
197 if (res != ERROR_SUCCESS) goto error_close_iid_key;
200 error_close_iid_key:
201 RegCloseKey(iid_key);
204 error_close_interface_key:
205 RegCloseKey(interface_key);
206 error_return:
207 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
210 /***********************************************************************
211 * unregister_interfaces
213 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
215 LONG res = ERROR_SUCCESS;
216 HKEY interface_key;
218 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
219 KEY_READ | KEY_WRITE, &interface_key);
220 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
221 if (res != ERROR_SUCCESS) goto error_return;
223 for (; res == ERROR_SUCCESS && list->iid; ++list) {
224 WCHAR buf[39];
226 StringFromGUID2(list->iid, buf, 39);
227 res = recursive_delete_keyW(interface_key, buf);
230 RegCloseKey(interface_key);
231 error_return:
232 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
235 /***********************************************************************
236 * register_coclasses
238 static HRESULT register_coclasses(struct regsvr_coclass const *list)
240 LONG res = ERROR_SUCCESS;
241 HKEY coclass_key;
243 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
244 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
245 if (res != ERROR_SUCCESS) goto error_return;
247 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
248 WCHAR buf[39];
249 HKEY clsid_key;
251 StringFromGUID2(list->clsid, buf, 39);
252 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
253 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
254 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
256 if (list->name) {
257 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
258 (CONST BYTE*)(list->name),
259 strlen(list->name) + 1);
260 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
263 if (list->ips) {
264 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
265 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
268 if (list->ips32) {
269 HKEY ips32_key;
271 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
272 KEY_READ | KEY_WRITE, NULL,
273 &ips32_key, NULL);
274 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
276 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
277 (CONST BYTE*)list->ips32,
278 lstrlenA(list->ips32) + 1);
279 if (res == ERROR_SUCCESS && list->ips32_tmodel)
280 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
281 (CONST BYTE*)list->ips32_tmodel,
282 strlen(list->ips32_tmodel) + 1);
283 RegCloseKey(ips32_key);
284 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
287 if (list->progid) {
288 char *buffer = NULL;
289 LPCSTR progid;
291 if (list->version) {
292 buffer = HeapAlloc(GetProcessHeap(), 0, strlen(list->progid) + strlen(list->version) + 2);
293 if (!buffer) {
294 res = ERROR_OUTOFMEMORY;
295 goto error_close_clsid_key;
297 strcpy(buffer, list->progid);
298 strcat(buffer, ".");
299 strcat(buffer, list->version);
300 progid = buffer;
301 } else
302 progid = list->progid;
303 res = register_key_defvalueA(clsid_key, progid_keyname,
304 progid);
305 HeapFree(GetProcessHeap(), 0, buffer);
306 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
308 if (list->version) {
309 res = register_key_defvalueA(clsid_key, versionindependentprogid_keyname,
310 list->progid);
311 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
315 if (list->version) {
316 res = register_key_defvalueA(clsid_key, version_keyname,
317 list->version);
318 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
321 error_close_clsid_key:
322 RegCloseKey(clsid_key);
325 error_close_coclass_key:
326 RegCloseKey(coclass_key);
327 error_return:
328 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
331 /***********************************************************************
332 * unregister_coclasses
334 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
336 LONG res = ERROR_SUCCESS;
337 HKEY coclass_key;
339 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
340 KEY_READ | KEY_WRITE, &coclass_key);
341 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
342 if (res != ERROR_SUCCESS) goto error_return;
344 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
345 WCHAR buf[39];
347 StringFromGUID2(list->clsid, buf, 39);
348 res = recursive_delete_keyW(coclass_key, buf);
349 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
352 error_close_coclass_key:
353 RegCloseKey(coclass_key);
354 error_return:
355 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
358 /***********************************************************************
359 * register_progids
361 static HRESULT register_progids(struct progid const *list)
363 LONG res = ERROR_SUCCESS;
365 for (; res == ERROR_SUCCESS && list->name; ++list) {
366 WCHAR buf[39];
367 HKEY progid_key;
369 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->name, 0,
370 NULL, 0, KEY_READ | KEY_WRITE, NULL,
371 &progid_key, NULL);
372 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
374 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
375 (CONST BYTE*)list->description,
376 strlen(list->description) + 1);
377 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
379 StringFromGUID2(list->clsid, buf, 39);
381 res = register_key_defvalueW(progid_key, clsid_keyname, buf);
382 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
384 if (list->curver) {
385 res = register_key_defvalueA(progid_key, curver_keyname, list->curver);
386 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
389 error_close_clsid_key:
390 RegCloseKey(progid_key);
393 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
396 /***********************************************************************
397 * unregister_progids
399 static HRESULT unregister_progids(struct progid const *list)
401 LONG res = ERROR_SUCCESS;
403 for (; res == ERROR_SUCCESS && list->name; ++list) {
404 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->name);
407 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
410 /***********************************************************************
411 * regsvr_key_guid
413 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
415 WCHAR buf[39];
417 StringFromGUID2(guid, buf, 39);
418 return register_key_defvalueW(base, name, buf);
421 /***********************************************************************
422 * regsvr_key_defvalueW
424 static LONG register_key_defvalueW(
425 HKEY base,
426 WCHAR const *name,
427 WCHAR const *value)
429 LONG res;
430 HKEY key;
432 res = RegCreateKeyExW(base, name, 0, NULL, 0,
433 KEY_READ | KEY_WRITE, NULL, &key, NULL);
434 if (res != ERROR_SUCCESS) return res;
435 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
436 (lstrlenW(value) + 1) * sizeof(WCHAR));
437 RegCloseKey(key);
438 return res;
441 /***********************************************************************
442 * regsvr_key_defvalueA
444 static LONG register_key_defvalueA(
445 HKEY base,
446 WCHAR const *name,
447 char const *value)
449 LONG res;
450 HKEY key;
452 res = RegCreateKeyExW(base, name, 0, NULL, 0,
453 KEY_READ | KEY_WRITE, NULL, &key, NULL);
454 if (res != ERROR_SUCCESS) return res;
455 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
456 lstrlenA(value) + 1);
457 RegCloseKey(key);
458 return res;
461 /***********************************************************************
462 * recursive_delete_key
464 static LONG recursive_delete_key(HKEY key)
466 LONG res;
467 WCHAR subkey_name[MAX_PATH];
468 DWORD cName;
469 HKEY subkey;
471 for (;;) {
472 cName = sizeof(subkey_name) / sizeof(WCHAR);
473 res = RegEnumKeyExW(key, 0, subkey_name, &cName,
474 NULL, NULL, NULL, NULL);
475 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) {
476 res = ERROR_SUCCESS; /* presumably we're done enumerating */
477 break;
479 res = RegOpenKeyExW(key, subkey_name, 0,
480 KEY_READ | KEY_WRITE, &subkey);
481 if (res == ERROR_FILE_NOT_FOUND) continue;
482 if (res != ERROR_SUCCESS) break;
484 res = recursive_delete_key(subkey);
485 RegCloseKey(subkey);
486 if (res != ERROR_SUCCESS) break;
489 if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0);
490 return res;
493 /***********************************************************************
494 * recursive_delete_keyA
496 static LONG recursive_delete_keyA(HKEY base, char const *name)
498 LONG res;
499 HKEY key;
501 res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key);
502 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
503 if (res != ERROR_SUCCESS) return res;
504 res = recursive_delete_key(key);
505 RegCloseKey(key);
506 return res;
509 /***********************************************************************
510 * recursive_delete_keyW
512 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name)
514 LONG res;
515 HKEY key;
517 res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key);
518 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
519 if (res != ERROR_SUCCESS) return res;
520 res = recursive_delete_key(key);
521 RegCloseKey(key);
522 return res;
525 /***********************************************************************
526 * coclass list
528 static struct regsvr_coclass const coclass_list[] = {
529 { &CLSID_DOMDocument,
530 "XML DOM Document",
531 NULL,
532 "msxml3.dll",
533 "Both",
534 "Microsoft.XMLDOM",
535 "1.0"
537 { &CLSID_DOMDocument2,
538 "XML DOM Document",
539 NULL,
540 "msxml3.dll",
541 "Both",
542 "Msxml2.DOMDocument",
543 "3.0"
545 { &CLSID_DOMDocument30,
546 "XML DOM Document 3.0",
547 NULL,
548 "msxml3.dll",
549 "Both",
550 "Msxml2.DOMDocument",
551 "3.0"
553 { &CLSID_DOMFreeThreadedDocument,
554 "Free threaded XML DOM Document",
555 NULL,
556 "msxml3.dll",
557 "Both",
558 "Microsoft.FreeThreadedXMLDOM",
559 "1.0"
561 { &CLSID_XMLHTTPRequest,
562 "XML HTTP Request",
563 NULL,
564 "msxml3.dll",
565 "Apartment",
566 "Microsoft.XMLHTTP",
567 "1.0"
569 { &CLSID_XMLDSOControl,
570 "XML Data Source Object",
571 NULL,
572 "msxml3.dll",
573 "Apartment",
574 "Microsoft.XMLDSO",
575 "1.0"
577 { &CLSID_XMLDocument,
578 "Msxml",
579 NULL,
580 "msxml3.dll",
581 "Both",
582 "Msxml"
584 { NULL } /* list terminator */
587 /***********************************************************************
588 * interface list
590 static struct regsvr_interface const interface_list[] = {
591 { NULL } /* list terminator */
594 /***********************************************************************
595 * progid list
597 static struct progid const progid_list[] = {
598 { "Microsoft.XMLDOM",
599 "XML DOM Document",
600 &CLSID_DOMDocument,
601 "Microsoft.XMLDOM.1.0"
603 { "Microsoft.XMLDOM.1.0",
604 "XML DOM Document",
605 &CLSID_DOMDocument,
606 NULL
608 { "MSXML.DOMDocument",
609 "XML DOM Document",
610 &CLSID_DOMDocument,
611 "Microsoft.XMLDOM.1.0"
613 { "Msxml2.DOMDocument",
614 "XML DOM Document",
615 &CLSID_DOMDocument2,
616 "Msxml2.DOMDocument.3.0"
618 { "Msxml2.DOMDocument.3.0",
619 "XML DOM Document 3.0",
620 &CLSID_DOMDocument30,
621 NULL
623 { "Microsoft.FreeThreadedXMLDOM",
624 "Free threaded XML DOM Document",
625 &CLSID_DOMFreeThreadedDocument,
626 "Microsoft.FreeThreadedXMLDOM.1.0"
628 { "Microsoft.FreeThreadedXMLDOM.1.0",
629 "Free threaded XML DOM Document",
630 &CLSID_DOMFreeThreadedDocument,
631 NULL
633 { "MSXML.FreeThreadedDOMDocument",
634 "Free threaded XML DOM Document",
635 &CLSID_DOMFreeThreadedDocument,
636 "Microsoft.FreeThreadedXMLDOM.1.0"
638 { "Microsoft.XMLHTTP",
639 "XML HTTP Request",
640 &CLSID_XMLHTTPRequest,
641 "Microsoft.XMLHTTP.1.0"
643 { "Microsoft.XMLHTTP.1.0",
644 "XML HTTP Request",
645 &CLSID_XMLHTTPRequest,
646 NULL
648 { "Microsoft.XMLDSO",
649 "XML Data Source Object",
650 &CLSID_XMLDSOControl,
651 "Microsoft.XMLDSO.1.0"
653 { "Microsoft.XMLDSO.1.0",
654 "XML Data Source Object",
655 &CLSID_XMLDSOControl,
656 NULL
658 { "Msxml",
659 "Msxml",
660 &CLSID_XMLDocument,
661 NULL
663 { NULL } /* list terminator */
666 /***********************************************************************
667 * DllRegisterServer (OLEAUT32.@)
669 HRESULT WINAPI DllRegisterServer(void)
671 HRESULT hr;
673 TRACE("\n");
675 hr = register_coclasses(coclass_list);
676 if (SUCCEEDED(hr))
677 hr = register_interfaces(interface_list);
678 if (SUCCEEDED(hr))
679 hr = register_progids(progid_list);
680 return hr;
683 /***********************************************************************
684 * DllUnregisterServer (OLEAUT32.@)
686 HRESULT WINAPI DllUnregisterServer(void)
688 HRESULT hr;
690 TRACE("\n");
692 hr = unregister_coclasses(coclass_list);
693 if (SUCCEEDED(hr))
694 hr = unregister_interfaces(interface_list);
695 if (SUCCEEDED(hr))
696 hr = unregister_progids(progid_list);
697 return hr;