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
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
);
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
);
83 LPCSTR name
; /* NULL for end of list */
84 LPCSTR description
; /* can be NULL to omit */
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',
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',
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',
113 static WCHAR
const ips32_keyname
[15] = {
114 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
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
,
134 static LONG
register_key_defvalueA(HKEY base
, WCHAR
const *name
,
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
;
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
) {
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
;
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 };
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
,
184 (lstrlenW(buf
) + 1) * sizeof(WCHAR
));
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
;
201 RegCloseKey(iid_key
);
204 error_close_interface_key
:
205 RegCloseKey(interface_key
);
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
;
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
) {
226 StringFromGUID2(list
->iid
, buf
, 39);
227 res
= recursive_delete_keyW(interface_key
, buf
);
230 RegCloseKey(interface_key
);
232 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
235 /***********************************************************************
238 static HRESULT
register_coclasses(struct regsvr_coclass
const *list
)
240 LONG res
= ERROR_SUCCESS
;
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
) {
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
;
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
;
264 res
= register_key_defvalueA(clsid_key
, ips_keyname
, list
->ips
);
265 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
271 res
= RegCreateKeyExW(clsid_key
, ips32_keyname
, 0, NULL
, 0,
272 KEY_READ
| KEY_WRITE
, 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
;
292 buffer
= HeapAlloc(GetProcessHeap(), 0, strlen(list
->progid
) + strlen(list
->version
) + 2);
294 res
= ERROR_OUTOFMEMORY
;
295 goto error_close_clsid_key
;
297 strcpy(buffer
, list
->progid
);
299 strcat(buffer
, list
->version
);
302 progid
= list
->progid
;
303 res
= register_key_defvalueA(clsid_key
, progid_keyname
,
305 HeapFree(GetProcessHeap(), 0, buffer
);
306 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
309 res
= register_key_defvalueA(clsid_key
, versionindependentprogid_keyname
,
311 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
316 res
= register_key_defvalueA(clsid_key
, version_keyname
,
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
);
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
;
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
) {
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
);
355 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
358 /***********************************************************************
361 static HRESULT
register_progids(struct progid
const *list
)
363 LONG res
= ERROR_SUCCESS
;
365 for (; res
== ERROR_SUCCESS
&& list
->name
; ++list
) {
369 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, list
->name
, 0,
370 NULL
, 0, KEY_READ
| KEY_WRITE
, 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
;
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 /***********************************************************************
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 /***********************************************************************
413 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
)
417 StringFromGUID2(guid
, buf
, 39);
418 return register_key_defvalueW(base
, name
, buf
);
421 /***********************************************************************
422 * regsvr_key_defvalueW
424 static LONG
register_key_defvalueW(
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
));
441 /***********************************************************************
442 * regsvr_key_defvalueA
444 static LONG
register_key_defvalueA(
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);
461 /***********************************************************************
462 * recursive_delete_key
464 static LONG
recursive_delete_key(HKEY key
)
467 WCHAR subkey_name
[MAX_PATH
];
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 */
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
);
486 if (res
!= ERROR_SUCCESS
) break;
489 if (res
== ERROR_SUCCESS
) res
= RegDeleteKeyW(key
, 0);
493 /***********************************************************************
494 * recursive_delete_keyA
496 static LONG
recursive_delete_keyA(HKEY base
, char const *name
)
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
);
509 /***********************************************************************
510 * recursive_delete_keyW
512 static LONG
recursive_delete_keyW(HKEY base
, WCHAR
const *name
)
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
);
525 /***********************************************************************
528 static struct regsvr_coclass
const coclass_list
[] = {
529 { &CLSID_DOMDocument
,
537 { &CLSID_DOMDocument2
,
542 "Msxml2.DOMDocument",
545 { &CLSID_DOMDocument30
,
546 "XML DOM Document 3.0",
550 "Msxml2.DOMDocument",
553 { &CLSID_DOMFreeThreadedDocument
,
554 "Free threaded XML DOM Document",
558 "Microsoft.FreeThreadedXMLDOM",
561 { &CLSID_XMLHTTPRequest
,
569 { &CLSID_XMLDSOControl
,
570 "XML Data Source Object",
577 { &CLSID_XMLDocument
,
584 { NULL
} /* list terminator */
587 /***********************************************************************
590 static struct regsvr_interface
const interface_list
[] = {
591 { NULL
} /* list terminator */
594 /***********************************************************************
597 static struct progid
const progid_list
[] = {
598 { "Microsoft.XMLDOM",
601 "Microsoft.XMLDOM.1.0"
603 { "Microsoft.XMLDOM.1.0",
608 { "MSXML.DOMDocument",
611 "Microsoft.XMLDOM.1.0"
613 { "Msxml2.DOMDocument",
616 "Msxml2.DOMDocument.3.0"
618 { "Msxml2.DOMDocument.3.0",
619 "XML DOM Document 3.0",
620 &CLSID_DOMDocument30
,
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
,
633 { "MSXML.FreeThreadedDOMDocument",
634 "Free threaded XML DOM Document",
635 &CLSID_DOMFreeThreadedDocument
,
636 "Microsoft.FreeThreadedXMLDOM.1.0"
638 { "Microsoft.XMLHTTP",
640 &CLSID_XMLHTTPRequest
,
641 "Microsoft.XMLHTTP.1.0"
643 { "Microsoft.XMLHTTP.1.0",
645 &CLSID_XMLHTTPRequest
,
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
,
663 { NULL
} /* list terminator */
666 /***********************************************************************
667 * DllRegisterServer (OLEAUT32.@)
669 HRESULT WINAPI
DllRegisterServer(void)
675 hr
= register_coclasses(coclass_list
);
677 hr
= register_interfaces(interface_list
);
679 hr
= register_progids(progid_list
);
683 /***********************************************************************
684 * DllUnregisterServer (OLEAUT32.@)
686 HRESULT WINAPI
DllUnregisterServer(void)
692 hr
= unregister_coclasses(coclass_list
);
694 hr
= unregister_interfaces(interface_list
);
696 hr
= unregister_progids(progid_list
);