2 * MSXML3 self-registerable dll functions
4 * Copyright (C) 2003 John K. Hohm
5 * Copyright (C) 2006 Robert Shearman
6 * Copyright (C) 2008 Alistair Leslie-Hughes
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
41 /* undef the #define in msxml2 so that we can access the v.2 version
42 independent CLSID as well as the v.3 one. */
43 #undef CLSID_DOMDocument
45 #include "msxml_private.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(ole);
52 * Near the bottom of this file are the exported DllRegisterServer and
53 * DllUnregisterServer, which make all this worthwhile.
56 /***********************************************************************
57 * interface for self-registering
59 struct regsvr_interface
61 IID const *iid; /* NULL for end of list */
62 LPCSTR name; /* can be NULL to omit */
63 IID const *base_iid; /* can be NULL to omit */
64 int num_methods; /* can be <0 to omit */
65 CLSID const *ps_clsid; /* can be NULL to omit */
66 CLSID const *ps_clsid32; /* can be NULL to omit */
69 static HRESULT register_interfaces(struct regsvr_interface const *list);
70 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
74 CLSID const *clsid; /* NULL for end of list */
75 LPCSTR name; /* can be NULL to omit */
76 LPCSTR ips; /* can be NULL to omit */
77 LPCSTR ips32; /* can be NULL to omit */
78 LPCSTR ips32_tmodel; /* can be NULL to omit */
79 LPCSTR progid; /* can be NULL to omit */
80 LPCSTR version; /* can be NULL to omit */
83 static HRESULT register_coclasses(struct regsvr_coclass const *list);
84 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
88 LPCSTR name; /* NULL for end of list */
89 LPCSTR description; /* can be NULL to omit */
91 LPCSTR curver; /* can be NULL to omit */
94 static HRESULT register_progids(struct progid const *list);
95 static HRESULT unregister_progids(struct progid const *list);
97 /***********************************************************************
98 * static string constants
100 static WCHAR const interface_keyname[10] = {
101 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
102 static WCHAR const base_ifa_keyname[14] = {
103 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
105 static WCHAR const num_methods_keyname[11] = {
106 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
107 static WCHAR const ps_clsid_keyname[15] = {
108 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
110 static WCHAR const ps_clsid32_keyname[17] = {
111 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
112 'i', 'd', '3', '2', 0 };
113 static WCHAR const clsid_keyname[6] = {
114 'C', 'L', 'S', 'I', 'D', 0 };
115 static WCHAR const ips_keyname[13] = {
116 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
118 static WCHAR const ips32_keyname[15] = {
119 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
121 static WCHAR const progid_keyname[7] = {
122 'P', 'r', 'o', 'g', 'I', 'D', 0 };
123 static WCHAR const versionindependentprogid_keyname[] = {
124 'V', 'e', 'r', 's', 'i', 'o', 'n',
125 'I', 'n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 't',
126 'P', 'r', 'o', 'g', 'I', 'D', 0 };
127 static WCHAR const version_keyname[] = {
128 'V', 'e', 'r', 's', 'i', 'o', 'n', 0 };
129 static WCHAR const curver_keyname[] = {
130 'C', 'u', 'r', 'V', 'e', 'r', 0 };
131 static char const tmodel_valuename[] = "ThreadingModel";
133 /***********************************************************************
134 * static helper functions
136 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
137 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
139 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
142 /***********************************************************************
143 * register_interfaces
145 static HRESULT register_interfaces(struct regsvr_interface const *list)
147 LONG res = ERROR_SUCCESS;
150 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
151 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
152 if (res != ERROR_SUCCESS) goto error_return;
154 for (; res == ERROR_SUCCESS && list->iid; ++list) {
158 StringFromGUID2(list->iid, buf, 39);
159 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
160 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
161 if (res != ERROR_SUCCESS) goto error_close_interface_key;
164 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
165 (CONST BYTE*)(list->name),
166 strlen(list->name) + 1);
167 if (res != ERROR_SUCCESS) goto error_close_iid_key;
170 if (list->base_iid) {
171 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
172 if (res != ERROR_SUCCESS) goto error_close_iid_key;
175 if (0 <= list->num_methods) {
176 static WCHAR const fmt[3] = { '%', 'd', 0 };
179 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
180 KEY_READ | KEY_WRITE, NULL, &key, NULL);
181 if (res != ERROR_SUCCESS) goto error_close_iid_key;
183 wsprintfW(buf, fmt, list->num_methods);
184 res = RegSetValueExW(key, NULL, 0, REG_SZ,
186 (lstrlenW(buf) + 1) * sizeof(WCHAR));
189 if (res != ERROR_SUCCESS) goto error_close_iid_key;
192 if (list->ps_clsid) {
193 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
194 if (res != ERROR_SUCCESS) goto error_close_iid_key;
197 if (list->ps_clsid32) {
198 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
199 if (res != ERROR_SUCCESS) goto error_close_iid_key;
203 RegCloseKey(iid_key);
206 error_close_interface_key:
207 RegCloseKey(interface_key);
209 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
212 /***********************************************************************
213 * unregister_interfaces
215 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
217 LONG res = ERROR_SUCCESS;
220 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
221 KEY_READ | KEY_WRITE, &interface_key);
222 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
223 if (res != ERROR_SUCCESS) goto error_return;
225 for (; res == ERROR_SUCCESS && list->iid; ++list) {
228 StringFromGUID2(list->iid, buf, 39);
229 res = RegDeleteTreeW(interface_key, buf);
230 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
233 RegCloseKey(interface_key);
235 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
238 /***********************************************************************
241 static HRESULT register_coclasses(struct regsvr_coclass const *list)
243 LONG res = ERROR_SUCCESS;
246 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
247 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
248 if (res != ERROR_SUCCESS) goto error_return;
250 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
254 StringFromGUID2(list->clsid, buf, 39);
255 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
256 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
257 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
260 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
261 (CONST BYTE*)(list->name),
262 strlen(list->name) + 1);
263 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
267 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
268 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
274 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
275 KEY_READ | KEY_WRITE, NULL,
277 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
279 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
280 (CONST BYTE*)list->ips32,
281 lstrlenA(list->ips32) + 1);
282 if (res == ERROR_SUCCESS && list->ips32_tmodel)
283 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
284 (CONST BYTE*)list->ips32_tmodel,
285 strlen(list->ips32_tmodel) + 1);
286 RegCloseKey(ips32_key);
287 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
295 buffer = HeapAlloc(GetProcessHeap(), 0, strlen(list->progid) + strlen(list->version) + 2);
297 res = ERROR_OUTOFMEMORY;
298 goto error_close_clsid_key;
300 strcpy(buffer, list->progid);
302 strcat(buffer, list->version);
305 progid = list->progid;
306 res = register_key_defvalueA(clsid_key, progid_keyname,
308 HeapFree(GetProcessHeap(), 0, buffer);
309 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
312 res = register_key_defvalueA(clsid_key, versionindependentprogid_keyname,
314 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
319 res = register_key_defvalueA(clsid_key, version_keyname,
321 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
324 error_close_clsid_key:
325 RegCloseKey(clsid_key);
328 error_close_coclass_key:
329 RegCloseKey(coclass_key);
331 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
334 /***********************************************************************
335 * unregister_coclasses
337 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
339 LONG res = ERROR_SUCCESS;
342 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
343 KEY_READ | KEY_WRITE, &coclass_key);
344 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
345 if (res != ERROR_SUCCESS) goto error_return;
347 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
350 StringFromGUID2(list->clsid, buf, 39);
351 res = RegDeleteTreeW(coclass_key, buf);
352 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
353 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
356 error_close_coclass_key:
357 RegCloseKey(coclass_key);
359 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
362 /***********************************************************************
365 static HRESULT register_progids(struct progid const *list)
367 LONG res = ERROR_SUCCESS;
369 for (; res == ERROR_SUCCESS && list->name; ++list) {
373 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->name, 0,
374 NULL, 0, KEY_READ | KEY_WRITE, NULL,
376 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
378 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
379 (CONST BYTE*)list->description,
380 strlen(list->description) + 1);
381 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
383 StringFromGUID2(list->clsid, buf, 39);
385 res = register_key_defvalueW(progid_key, clsid_keyname, buf);
386 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
389 res = register_key_defvalueA(progid_key, curver_keyname, list->curver);
390 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
393 error_close_clsid_key:
394 RegCloseKey(progid_key);
397 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
400 /***********************************************************************
403 static HRESULT unregister_progids(struct progid const *list)
405 LONG res = ERROR_SUCCESS;
407 for (; res == ERROR_SUCCESS && list->name; ++list) {
408 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->name);
409 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
412 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
415 /***********************************************************************
418 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
422 StringFromGUID2(guid, buf, 39);
423 return register_key_defvalueW(base, name, buf);
426 /***********************************************************************
427 * regsvr_key_defvalueW
429 static LONG register_key_defvalueW(
437 res = RegCreateKeyExW(base, name, 0, NULL, 0,
438 KEY_READ | KEY_WRITE, NULL, &key, NULL);
439 if (res != ERROR_SUCCESS) return res;
440 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
441 (lstrlenW(value) + 1) * sizeof(WCHAR));
446 /***********************************************************************
447 * regsvr_key_defvalueA
449 static LONG register_key_defvalueA(
457 res = RegCreateKeyExW(base, name, 0, NULL, 0,
458 KEY_READ | KEY_WRITE, NULL, &key, NULL);
459 if (res != ERROR_SUCCESS) return res;
460 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
461 lstrlenA(value) + 1);
466 /***********************************************************************
469 static struct regsvr_coclass const coclass_list[] = {
470 { &CLSID_DOMDocument,
478 { &CLSID_DOMDocument2,
483 "Msxml2.DOMDocument",
486 { &CLSID_DOMDocument30,
487 "XML DOM Document 3.0",
491 "Msxml2.DOMDocument",
494 { &CLSID_DOMFreeThreadedDocument,
495 "Free threaded XML DOM Document",
499 "Microsoft.FreeThreadedXMLDOM",
502 { &CLSID_DOMFreeThreadedDocument,
503 "Free threaded XML DOM Document",
507 "Microsoft.FreeThreadedXMLDOM",
510 { &CLSID_FreeThreadedDOMDocument,
511 "Free Threaded XML DOM Document",
515 "Microsoft.FreeThreadedXMLDOM.1.0",
519 { &CLSID_XMLHTTPRequest,
527 { &CLSID_XMLDSOControl,
528 "XML Data Source Object",
535 { &CLSID_XMLDocument,
542 { &CLSID_XMLSchemaCache,
547 "Msxml2.XMLSchemaCache",
550 { &CLSID_XMLSchemaCache30,
551 "XML Schema Cache 3.0",
555 "Msxml2.XMLSchemaCache",
558 { &CLSID_SAXXMLReader,
563 "Msxml2.SAXXMLReader",
566 { NULL } /* list terminator */
569 /***********************************************************************
572 static struct regsvr_interface const interface_list[] = {
573 { NULL } /* list terminator */
576 /***********************************************************************
579 static struct progid const progid_list[] = {
580 { "Microsoft.XMLDOM",
583 "Microsoft.XMLDOM.1.0"
585 { "Microsoft.XMLDOM.1.0",
590 { "MSXML.DOMDocument",
593 "Microsoft.XMLDOM.1.0"
595 { "Msxml2.DOMDocument",
598 "Msxml2.DOMDocument.3.0"
600 { "Msxml2.DOMDocument.3.0",
601 "XML DOM Document 3.0",
602 &CLSID_DOMDocument30,
605 { "Microsoft.FreeThreadedXMLDOM",
606 "Free threaded XML DOM Document",
607 &CLSID_DOMFreeThreadedDocument,
608 "Microsoft.FreeThreadedXMLDOM.1.0"
610 { "Microsoft.FreeThreadedXMLDOM.1.0",
611 "Free threaded XML DOM Document",
612 &CLSID_DOMFreeThreadedDocument,
615 { "MSXML.FreeThreadedDOMDocument",
616 "Free threaded XML DOM Document",
617 &CLSID_DOMFreeThreadedDocument,
618 "Microsoft.FreeThreadedXMLDOM.1.0"
620 { "Microsoft.XMLHTTP",
622 &CLSID_XMLHTTPRequest,
623 "Microsoft.XMLHTTP.1.0"
625 { "Microsoft.XMLHTTP.1.0",
627 &CLSID_XMLHTTPRequest,
630 { "Microsoft.XMLDSO",
631 "XML Data Source Object",
632 &CLSID_XMLDSOControl,
633 "Microsoft.XMLDSO.1.0"
635 { "Microsoft.XMLDSO.1.0",
636 "XML Data Source Object",
637 &CLSID_XMLDSOControl,
645 { "Msxml2.XMLSchemaCache",
647 &CLSID_XMLSchemaCache,
648 "Msxml2.XMLSchemaCache.3.0"
650 { "Msxml2.XMLSchemaCache.3.0",
651 "XML Schema Cache 3.0",
652 &CLSID_XMLSchemaCache30,
656 { NULL } /* list terminator */
659 /***********************************************************************
660 * DllRegisterServer (OLEAUT32.@)
662 HRESULT WINAPI DllRegisterServer(void)
666 static const WCHAR wszMsXml3[] = {'m','s','x','m','l','3','.','d','l','l',0};
670 hr = register_coclasses(coclass_list);
672 hr = register_interfaces(interface_list);
674 hr = register_progids(progid_list);
678 hr = LoadTypeLibEx(wszMsXml3, REGKIND_REGISTER, &tl);
680 ITypeLib_Release(tl);
686 /***********************************************************************
687 * DllUnregisterServer (OLEAUT32.@)
689 HRESULT WINAPI DllUnregisterServer(void)
695 hr = unregister_coclasses(coclass_list);
697 hr = unregister_interfaces(interface_list);
699 hr = unregister_progids(progid_list);
701 hr = UnRegisterTypeLib(&LIBID_MSXML2, 3, 0, LOCALE_SYSTEM_DEFAULT, SYS_WIN32);