2 * self-registerable dll functions for ole32.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
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
39 * Near the bottom of this file are the exported DllRegisterServer and
40 * DllUnregisterServer, which make all this worthwhile.
43 /***********************************************************************
44 * interface for self-registering
46 struct regsvr_interface
48 IID
const *iid
; /* NULL for end of list */
49 LPCSTR name
; /* can be NULL to omit */
50 IID
const *base_iid
; /* can be NULL to omit */
51 int num_methods
; /* can be <0 to omit */
52 CLSID
const *ps_clsid
; /* can be NULL to omit */
53 CLSID
const *ps_clsid32
; /* can be NULL to omit */
56 static HRESULT
register_interfaces(struct regsvr_interface
const *list
);
57 static HRESULT
unregister_interfaces(struct regsvr_interface
const *list
);
61 CLSID
const *clsid
; /* NULL for end of list */
62 LPCSTR name
; /* can be NULL to omit */
63 LPCSTR ips
; /* can be NULL to omit */
64 LPCSTR ips32
; /* can be NULL to omit */
65 LPCSTR ips32_tmodel
; /* can be NULL to omit */
68 static HRESULT
register_coclasses(struct regsvr_coclass
const *list
);
69 static HRESULT
unregister_coclasses(struct regsvr_coclass
const *list
);
71 /***********************************************************************
72 * static string constants
74 static WCHAR
const interface_keyname
[10] = {
75 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
76 static WCHAR
const base_ifa_keyname
[14] = {
77 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
79 static WCHAR
const num_methods_keyname
[11] = {
80 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
81 static WCHAR
const ps_clsid_keyname
[15] = {
82 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
84 static WCHAR
const ps_clsid32_keyname
[17] = {
85 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
86 'i', 'd', '3', '2', 0 };
87 static WCHAR
const clsid_keyname
[6] = {
88 'C', 'L', 'S', 'I', 'D', 0 };
89 static WCHAR
const ips_keyname
[13] = {
90 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
92 static WCHAR
const ips32_keyname
[15] = {
93 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
95 static char const tmodel_valuename
[] = "ThreadingModel";
97 /***********************************************************************
98 * static helper functions
100 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
);
101 static LONG
register_key_defvalueW(HKEY base
, WCHAR
const *name
,
103 static LONG
register_key_defvalueA(HKEY base
, WCHAR
const *name
,
105 static LONG
recursive_delete_key(HKEY key
);
108 /***********************************************************************
109 * register_interfaces
111 static HRESULT
register_interfaces(struct regsvr_interface
const *list
)
113 LONG res
= ERROR_SUCCESS
;
116 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0, NULL
, 0,
117 KEY_READ
| KEY_WRITE
, NULL
, &interface_key
, NULL
);
118 if (res
!= ERROR_SUCCESS
) goto error_return
;
120 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
124 StringFromGUID2(list
->iid
, buf
, 39);
125 res
= RegCreateKeyExW(interface_key
, buf
, 0, NULL
, 0,
126 KEY_READ
| KEY_WRITE
, NULL
, &iid_key
, NULL
);
127 if (res
!= ERROR_SUCCESS
) goto error_close_interface_key
;
130 res
= RegSetValueExA(iid_key
, NULL
, 0, REG_SZ
,
131 (CONST BYTE
*)(list
->name
),
132 strlen(list
->name
) + 1);
133 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
136 if (list
->base_iid
) {
137 register_key_guid(iid_key
, base_ifa_keyname
, list
->base_iid
);
138 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
141 if (0 <= list
->num_methods
) {
142 static WCHAR
const fmt
[3] = { '%', 'd', 0 };
145 res
= RegCreateKeyExW(iid_key
, num_methods_keyname
, 0, NULL
, 0,
146 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
147 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
149 wsprintfW(buf
, fmt
, list
->num_methods
);
150 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
,
152 (lstrlenW(buf
) + 1) * sizeof(WCHAR
));
155 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
158 if (list
->ps_clsid
) {
159 register_key_guid(iid_key
, ps_clsid_keyname
, list
->ps_clsid
);
160 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
163 if (list
->ps_clsid32
) {
164 register_key_guid(iid_key
, ps_clsid32_keyname
, list
->ps_clsid32
);
165 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
169 RegCloseKey(iid_key
);
172 error_close_interface_key
:
173 RegCloseKey(interface_key
);
175 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
178 /***********************************************************************
179 * unregister_interfaces
181 static HRESULT
unregister_interfaces(struct regsvr_interface
const *list
)
183 LONG res
= ERROR_SUCCESS
;
186 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0,
187 KEY_READ
| KEY_WRITE
, &interface_key
);
188 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
189 if (res
!= ERROR_SUCCESS
) goto error_return
;
191 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
195 StringFromGUID2(list
->iid
, buf
, 39);
196 res
= RegOpenKeyExW(interface_key
, buf
, 0,
197 KEY_READ
| KEY_WRITE
, &iid_key
);
198 if (res
== ERROR_FILE_NOT_FOUND
) {
202 if (res
!= ERROR_SUCCESS
) goto error_close_interface_key
;
203 res
= recursive_delete_key(iid_key
);
204 RegCloseKey(iid_key
);
205 if (res
!= ERROR_SUCCESS
) goto error_close_interface_key
;
208 error_close_interface_key
:
209 RegCloseKey(interface_key
);
211 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
214 /***********************************************************************
217 static HRESULT
register_coclasses(struct regsvr_coclass
const *list
)
219 LONG res
= ERROR_SUCCESS
;
222 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0, NULL
, 0,
223 KEY_READ
| KEY_WRITE
, NULL
, &coclass_key
, NULL
);
224 if (res
!= ERROR_SUCCESS
) goto error_return
;
226 for (; res
== ERROR_SUCCESS
&& list
->clsid
; ++list
) {
230 StringFromGUID2(list
->clsid
, buf
, 39);
231 res
= RegCreateKeyExW(coclass_key
, buf
, 0, NULL
, 0,
232 KEY_READ
| KEY_WRITE
, NULL
, &clsid_key
, NULL
);
233 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
236 res
= RegSetValueExA(clsid_key
, NULL
, 0, REG_SZ
,
237 (CONST BYTE
*)(list
->name
),
238 strlen(list
->name
) + 1);
239 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
243 res
= register_key_defvalueA(clsid_key
, ips_keyname
, list
->ips
);
244 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
250 res
= RegCreateKeyExW(clsid_key
, ips32_keyname
, 0, NULL
, 0,
251 KEY_READ
| KEY_WRITE
, NULL
,
253 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
255 res
= RegSetValueExA(ips32_key
, NULL
, 0, REG_SZ
,
256 (CONST BYTE
*)list
->ips32
,
257 lstrlenA(list
->ips32
) + 1);
258 if (res
== ERROR_SUCCESS
&& list
->ips32_tmodel
)
259 res
= RegSetValueExA(ips32_key
, tmodel_valuename
, 0, REG_SZ
,
260 (CONST BYTE
*)list
->ips32_tmodel
,
261 strlen(list
->ips32_tmodel
) + 1);
262 RegCloseKey(ips32_key
);
263 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
266 error_close_clsid_key
:
267 RegCloseKey(clsid_key
);
270 error_close_coclass_key
:
271 RegCloseKey(coclass_key
);
273 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
276 /***********************************************************************
277 * unregister_coclasses
279 static HRESULT
unregister_coclasses(struct regsvr_coclass
const *list
)
281 LONG res
= ERROR_SUCCESS
;
284 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0,
285 KEY_READ
| KEY_WRITE
, &coclass_key
);
286 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
287 if (res
!= ERROR_SUCCESS
) goto error_return
;
289 for (; res
== ERROR_SUCCESS
&& list
->clsid
; ++list
) {
293 StringFromGUID2(list
->clsid
, buf
, 39);
294 res
= RegOpenKeyExW(coclass_key
, buf
, 0,
295 KEY_READ
| KEY_WRITE
, &clsid_key
);
296 if (res
== ERROR_FILE_NOT_FOUND
) {
300 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
301 res
= recursive_delete_key(clsid_key
);
302 RegCloseKey(clsid_key
);
303 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
306 error_close_coclass_key
:
307 RegCloseKey(coclass_key
);
309 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
312 /***********************************************************************
315 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
)
319 StringFromGUID2(guid
, buf
, 39);
320 return register_key_defvalueW(base
, name
, buf
);
323 /***********************************************************************
324 * regsvr_key_defvalueW
326 static LONG
register_key_defvalueW(
334 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
335 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
336 if (res
!= ERROR_SUCCESS
) return res
;
337 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
338 (lstrlenW(value
) + 1) * sizeof(WCHAR
));
343 /***********************************************************************
344 * regsvr_key_defvalueA
346 static LONG
register_key_defvalueA(
354 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
355 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
356 if (res
!= ERROR_SUCCESS
) return res
;
357 res
= RegSetValueExA(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
358 lstrlenA(value
) + 1);
363 /***********************************************************************
364 * recursive_delete_key
366 static LONG
recursive_delete_key(HKEY key
)
369 WCHAR subkey_name
[MAX_PATH
];
374 cName
= sizeof(subkey_name
) / sizeof(WCHAR
);
375 res
= RegEnumKeyExW(key
, 0, subkey_name
, &cName
,
376 NULL
, NULL
, NULL
, NULL
);
377 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) {
378 res
= ERROR_SUCCESS
; /* presumably we're done enumerating */
381 res
= RegOpenKeyExW(key
, subkey_name
, 0,
382 KEY_READ
| KEY_WRITE
, &subkey
);
383 if (res
== ERROR_FILE_NOT_FOUND
) continue;
384 if (res
!= ERROR_SUCCESS
) break;
386 res
= recursive_delete_key(subkey
);
388 if (res
!= ERROR_SUCCESS
) break;
391 if (res
== ERROR_SUCCESS
) res
= RegDeleteKeyW(key
, 0);
395 /***********************************************************************
398 static GUID
const CLSID_FileMoniker
= {
399 0x00000303, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
401 static GUID
const CLSID_ItemMoniker
= {
402 0x00000304, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
404 /* FIXME: DfMarshal and PSFactoryBuffer are defined elsewhere too */
406 static GUID
const CLSID_DfMarshal
= {
407 0x0000030B, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
409 static GUID
const CLSID_PSFactoryBuffer
= {
410 0x00000320, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
412 static struct regsvr_coclass
const coclass_list
[] = {
413 { &CLSID_FileMoniker
,
419 { &CLSID_ItemMoniker
,
431 { &CLSID_PSFactoryBuffer
,
437 { &CLSID_StdGlobalInterfaceTable
,
438 "StdGlobalInterfaceTable",
443 { NULL
} /* list terminator */
446 /***********************************************************************
450 /* FIXME: perhaps the interfaces that are proxied by another dll
451 * should be registered in that dll? Or maybe the choice of proxy is
452 * arbitrary at this point? */
454 static GUID
const CLSID_PSFactoryBuffer_ole2disp
= {
455 0x00020420, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
457 static GUID
const CLSID_PSFactoryBuffer_oleaut32
= {
458 0xB196B286, 0xBAB4, 0x101A, {0xB6,0x9C,0x00,0xAA,0x00,0x34,0x1D,0x07} };
460 /* FIXME: these interfaces should be defined in ocidl.idl */
462 static IID
const IID_IFontEventsDisp
= {
463 0x4EF6100A, 0xAF88, 0x11D0, {0x98,0x46,0x00,0xC0,0x4F,0xC2,0x99,0x93} };
465 static IID
const IID_IProvideMultipleClassInfo
= {
466 0xA7ABA9C1, 0x8983, 0x11CF, {0x8F,0x20,0x00,0x80,0x5F,0x2C,0xD0,0x64} };
468 static IID
const IID_IObjectWithSite
= {
469 0xFC4801A3, 0x2BA9, 0x11CF, {0xA2,0x29,0x00,0xAA,0x00,0x3D,0x73,0x52} };
471 static struct regsvr_interface
const interface_list
[] = {
477 &CLSID_PSFactoryBuffer
479 { &IID_IClassFactory
,
484 &CLSID_PSFactoryBuffer
491 &CLSID_PSFactoryBuffer
498 &CLSID_PSFactoryBuffer
500 { &IID_IPersistStorage
,
505 &CLSID_PSFactoryBuffer
512 &CLSID_PSFactoryBuffer
519 &CLSID_PSFactoryBuffer
526 &CLSID_PSFactoryBuffer
528 { &IID_IOleClientSite
,
533 &CLSID_PSFactoryBuffer
539 &CLSID_PSFactoryBuffer_ole2disp
,
540 &CLSID_PSFactoryBuffer_ole2disp
547 &CLSID_PSFactoryBuffer_ole2disp
554 &CLSID_PSFactoryBuffer_ole2disp
556 { &IID_IPropertyPage2
,
561 &CLSID_PSFactoryBuffer_oleaut32
568 &CLSID_PSFactoryBuffer_oleaut32
570 { &IID_ICreateErrorInfo
,
575 &CLSID_PSFactoryBuffer_oleaut32
577 { &IID_IPersistPropertyBag2
,
578 "IPersistPropertyBag2",
582 &CLSID_PSFactoryBuffer_oleaut32
584 { &IID_IPropertyBag2
,
589 &CLSID_PSFactoryBuffer_oleaut32
596 &CLSID_PSFactoryBuffer_oleaut32
598 { &IID_IPerPropertyBrowsing
,
599 "IPerPropertyBrowsing",
603 &CLSID_PSFactoryBuffer_oleaut32
605 { &IID_IPersistPropertyBag
,
606 "IPersistPropertyBag",
610 &CLSID_PSFactoryBuffer_oleaut32
612 { &IID_IAdviseSinkEx
,
617 &CLSID_PSFactoryBuffer_oleaut32
619 { &IID_IFontEventsDisp
,
624 &CLSID_PSFactoryBuffer_oleaut32
631 &CLSID_PSFactoryBuffer_oleaut32
633 { &IID_IPointerInactive
,
638 &CLSID_PSFactoryBuffer_oleaut32
640 { &IID_ISimpleFrameSite
,
645 &CLSID_PSFactoryBuffer_oleaut32
652 &CLSID_PSFactoryBuffer_oleaut32
659 &CLSID_PSFactoryBuffer_oleaut32
661 { &IID_IPersistStreamInit
,
662 "IPersistStreamInit",
666 &CLSID_PSFactoryBuffer_oleaut32
673 &CLSID_PSFactoryBuffer_oleaut32
675 { &IID_IPropertyNotifySink
,
676 "IPropertyNotifySink",
680 &CLSID_PSFactoryBuffer_oleaut32
682 { &IID_IOleInPlaceSiteEx
,
687 &CLSID_PSFactoryBuffer_oleaut32
689 { &IID_IOleParentUndoUnit
,
690 "IOleParentUndoUnit",
694 &CLSID_PSFactoryBuffer_oleaut32
696 { &IID_IProvideClassInfo2
,
697 "IProvideClassInfo2",
701 &CLSID_PSFactoryBuffer_oleaut32
703 { &IID_IProvideMultipleClassInfo
,
704 "IProvideMultipleClassInfo",
708 &CLSID_PSFactoryBuffer_oleaut32
710 { &IID_IProvideClassInfo
,
715 &CLSID_PSFactoryBuffer_oleaut32
717 { &IID_IConnectionPointContainer
,
718 "IConnectionPointContainer",
722 &CLSID_PSFactoryBuffer_oleaut32
724 { &IID_IEnumConnectionPoints
,
725 "IEnumConnectionPoints",
729 &CLSID_PSFactoryBuffer_oleaut32
731 { &IID_IConnectionPoint
,
736 &CLSID_PSFactoryBuffer_oleaut32
738 { &IID_IEnumConnections
,
743 &CLSID_PSFactoryBuffer_oleaut32
750 &CLSID_PSFactoryBuffer_oleaut32
752 { &IID_IOleControlSite
,
757 &CLSID_PSFactoryBuffer_oleaut32
759 { &IID_ISpecifyPropertyPages
,
760 "ISpecifyPropertyPages",
764 &CLSID_PSFactoryBuffer_oleaut32
766 { &IID_IPropertyPageSite
,
771 &CLSID_PSFactoryBuffer_oleaut32
773 { &IID_IPropertyPage
,
778 &CLSID_PSFactoryBuffer_oleaut32
780 { &IID_IClassFactory2
,
785 &CLSID_PSFactoryBuffer_oleaut32
787 { &IID_IEnumOleUndoUnits
,
792 &CLSID_PSFactoryBuffer_oleaut32
794 { &IID_IPersistMemory
,
799 &CLSID_PSFactoryBuffer_oleaut32
806 &CLSID_PSFactoryBuffer_oleaut32
813 &CLSID_PSFactoryBuffer_oleaut32
815 { &IID_IQuickActivate
,
820 &CLSID_PSFactoryBuffer_oleaut32
822 { &IID_IOleUndoManager
,
827 &CLSID_PSFactoryBuffer_oleaut32
829 { &IID_IObjectWithSite
,
834 &CLSID_PSFactoryBuffer_oleaut32
836 { NULL
} /* list terminator */
839 /***********************************************************************
840 * DllRegisterServer (OLE32.194)
842 HRESULT WINAPI
OLE32_DllRegisterServer()
848 hr
= register_coclasses(coclass_list
);
850 hr
= register_interfaces(interface_list
);
854 /***********************************************************************
855 * DllUnregisterServer (OLE32.@)
857 HRESULT WINAPI
OLE32_DllUnregisterServer()
863 hr
= unregister_coclasses(coclass_list
);
865 hr
= unregister_interfaces(interface_list
);