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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include "compobj_private.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
46 * Near the bottom of this file are the exported DllRegisterServer and
47 * DllUnregisterServer, which make all this worthwhile.
50 /***********************************************************************
51 * interface for self-registering
53 struct regsvr_interface
55 IID
const *iid
; /* NULL for end of list */
56 LPCSTR name
; /* can be NULL to omit */
57 IID
const *base_iid
; /* can be NULL to omit */
58 int num_methods
; /* can be <0 to omit */
59 CLSID
const *ps_clsid
; /* can be NULL to omit */
60 CLSID
const *ps_clsid32
; /* can be NULL to omit */
63 static HRESULT
register_interfaces(struct regsvr_interface
const *list
);
64 static HRESULT
unregister_interfaces(struct regsvr_interface
const *list
);
68 CLSID
const *clsid
; /* NULL for end of list */
69 LPCSTR name
; /* can be NULL to omit */
70 LPCSTR ips
; /* can be NULL to omit */
71 LPCSTR ips32
; /* can be NULL to omit */
72 LPCSTR ips32_tmodel
; /* can be NULL to omit */
73 LPCSTR progid
; /* can be NULL to omit */
76 static HRESULT
register_coclasses(struct regsvr_coclass
const *list
);
77 static HRESULT
unregister_coclasses(struct regsvr_coclass
const *list
);
79 /***********************************************************************
80 * static string constants
82 static WCHAR
const interface_keyname
[10] = {
83 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
84 static WCHAR
const base_ifa_keyname
[14] = {
85 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
87 static WCHAR
const num_methods_keyname
[11] = {
88 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
89 static WCHAR
const ps_clsid_keyname
[15] = {
90 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
92 static WCHAR
const ps_clsid32_keyname
[17] = {
93 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
94 'i', 'd', '3', '2', 0 };
95 static WCHAR
const clsid_keyname
[6] = {
96 'C', 'L', 'S', 'I', 'D', 0 };
97 static WCHAR
const ips_keyname
[13] = {
98 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
100 static WCHAR
const ips32_keyname
[15] = {
101 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
103 static WCHAR
const progid_keyname
[7] = {
104 'P', 'r', 'o', 'g', 'I', 'D', 0 };
105 static char const tmodel_valuename
[] = "ThreadingModel";
107 /***********************************************************************
108 * static helper functions
110 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
);
111 static LONG
register_key_defvalueW(HKEY base
, WCHAR
const *name
,
113 static LONG
register_key_defvalueA(HKEY base
, WCHAR
const *name
,
115 static LONG
register_progid(WCHAR
const *clsid
, char const *progid
,
118 /***********************************************************************
119 * register_interfaces
121 static HRESULT
register_interfaces(struct regsvr_interface
const *list
)
123 LONG res
= ERROR_SUCCESS
;
126 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0, NULL
, 0,
127 KEY_READ
| KEY_WRITE
, NULL
, &interface_key
, NULL
);
128 if (res
!= ERROR_SUCCESS
) goto error_return
;
130 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
134 StringFromGUID2(list
->iid
, buf
, 39);
135 res
= RegCreateKeyExW(interface_key
, buf
, 0, NULL
, 0,
136 KEY_READ
| KEY_WRITE
, NULL
, &iid_key
, NULL
);
137 if (res
!= ERROR_SUCCESS
) goto error_close_interface_key
;
140 res
= RegSetValueExA(iid_key
, NULL
, 0, REG_SZ
,
141 (CONST BYTE
*)(list
->name
),
142 strlen(list
->name
) + 1);
143 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
146 if (list
->base_iid
) {
147 res
= register_key_guid(iid_key
, base_ifa_keyname
, list
->base_iid
);
148 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
151 if (0 <= list
->num_methods
) {
152 static WCHAR
const fmt
[3] = { '%', 'd', 0 };
155 res
= RegCreateKeyExW(iid_key
, num_methods_keyname
, 0, NULL
, 0,
156 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
157 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
159 sprintfW(buf
, fmt
, list
->num_methods
);
160 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
,
162 (lstrlenW(buf
) + 1) * sizeof(WCHAR
));
165 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
168 if (list
->ps_clsid
) {
169 res
= register_key_guid(iid_key
, ps_clsid_keyname
, list
->ps_clsid
);
170 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
173 if (list
->ps_clsid32
) {
174 res
= register_key_guid(iid_key
, ps_clsid32_keyname
, list
->ps_clsid32
);
175 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
179 RegCloseKey(iid_key
);
182 error_close_interface_key
:
183 RegCloseKey(interface_key
);
185 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
188 /***********************************************************************
189 * unregister_interfaces
191 static HRESULT
unregister_interfaces(struct regsvr_interface
const *list
)
193 LONG res
= ERROR_SUCCESS
;
196 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0,
197 KEY_READ
| KEY_WRITE
, &interface_key
);
198 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
199 if (res
!= ERROR_SUCCESS
) goto error_return
;
201 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
204 StringFromGUID2(list
->iid
, buf
, 39);
205 res
= RegDeleteTreeW(interface_key
, buf
);
206 if (res
== ERROR_FILE_NOT_FOUND
) res
= ERROR_SUCCESS
;
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
;
267 res
= register_key_defvalueA(clsid_key
, progid_keyname
,
269 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
271 res
= register_progid(buf
, list
->progid
, list
->name
);
272 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
275 error_close_clsid_key
:
276 RegCloseKey(clsid_key
);
279 error_close_coclass_key
:
280 RegCloseKey(coclass_key
);
282 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
285 /***********************************************************************
286 * unregister_coclasses
288 static HRESULT
unregister_coclasses(struct regsvr_coclass
const *list
)
290 LONG res
= ERROR_SUCCESS
;
293 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0,
294 KEY_READ
| KEY_WRITE
, &coclass_key
);
295 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
296 if (res
!= ERROR_SUCCESS
) goto error_return
;
298 for (; res
== ERROR_SUCCESS
&& list
->clsid
; ++list
) {
301 StringFromGUID2(list
->clsid
, buf
, 39);
302 res
= RegDeleteTreeW(coclass_key
, buf
);
303 if (res
== ERROR_FILE_NOT_FOUND
) res
= ERROR_SUCCESS
;
304 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
307 res
= RegDeleteTreeA(HKEY_CLASSES_ROOT
, list
->progid
);
308 if (res
== ERROR_FILE_NOT_FOUND
) res
= ERROR_SUCCESS
;
309 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
313 error_close_coclass_key
:
314 RegCloseKey(coclass_key
);
316 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
319 /***********************************************************************
322 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
)
326 StringFromGUID2(guid
, buf
, 39);
327 return register_key_defvalueW(base
, name
, buf
);
330 /***********************************************************************
331 * regsvr_key_defvalueW
333 static LONG
register_key_defvalueW(
341 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
342 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
343 if (res
!= ERROR_SUCCESS
) return res
;
344 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
345 (lstrlenW(value
) + 1) * sizeof(WCHAR
));
350 /***********************************************************************
351 * regsvr_key_defvalueA
353 static LONG
register_key_defvalueA(
361 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
362 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
363 if (res
!= ERROR_SUCCESS
) return res
;
364 res
= RegSetValueExA(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
365 lstrlenA(value
) + 1);
370 /***********************************************************************
373 static LONG
register_progid(
381 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, progid
, 0,
382 NULL
, 0, KEY_READ
| KEY_WRITE
, NULL
,
384 if (res
!= ERROR_SUCCESS
) return res
;
387 res
= RegSetValueExA(progid_key
, NULL
, 0, REG_SZ
,
388 (CONST BYTE
*)name
, strlen(name
) + 1);
389 if (res
!= ERROR_SUCCESS
) goto error_close_progid_key
;
393 res
= register_key_defvalueW(progid_key
, clsid_keyname
, clsid
);
394 if (res
!= ERROR_SUCCESS
) goto error_close_progid_key
;
397 error_close_progid_key
:
398 RegCloseKey(progid_key
);
402 /***********************************************************************
405 static GUID
const CLSID_StdOleLink
= {
406 0x00000300, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
408 static GUID
const CLSID_PackagerMoniker
= {
409 0x00000308, 0x0000, 0x0000, {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46} };
411 extern GUID
const CLSID_Picture_Metafile
;
412 extern GUID
const CLSID_Picture_Dib
;
414 static struct regsvr_coclass
const coclass_list
[] = {
421 { &CLSID_FileMoniker
,
428 { &CLSID_ItemMoniker
,
434 { &CLSID_AntiMoniker
,
440 { &CLSID_PointerMoniker
,
446 { &CLSID_PackagerMoniker
,
452 { &CLSID_CompositeMoniker
,
464 { &CLSID_Picture_Metafile
,
465 "Picture (Metafile)",
471 { &CLSID_Picture_Dib
,
472 "Picture (Device Independent Bitmap)",
478 { &CLSID_ClassMoniker
,
485 { &CLSID_PSFactoryBuffer
,
491 { &CLSID_StdGlobalInterfaceTable
,
492 "StdGlobalInterfaceTable",
497 { &CLSID_StdComponentCategoriesMgr
,
498 "Component Categories Manager",
503 { NULL
} /* list terminator */
506 /***********************************************************************
510 #define INTERFACE_ENTRY(interface, base) { &IID_##interface, #interface, base, sizeof(interface##Vtbl)/sizeof(void*), NULL, NULL }
512 static const struct regsvr_interface interface_list
[] = {
513 INTERFACE_ENTRY( IUnknown
, NULL
),
514 INTERFACE_ENTRY( IMalloc
, NULL
),
515 INTERFACE_ENTRY( IMarshal
, NULL
),
516 INTERFACE_ENTRY( IMoniker
, &IID_IPersistStream
),
517 INTERFACE_ENTRY( IMessageFilter
, NULL
),
518 INTERFACE_ENTRY( IStdMarshalInfo
, NULL
),
519 INTERFACE_ENTRY( IExternalConnection
, NULL
),
520 INTERFACE_ENTRY( IMallocSpy
, NULL
),
521 INTERFACE_ENTRY( IMultiQI
, NULL
),
522 INTERFACE_ENTRY( IPersistStream
, &IID_IPersist
),
523 INTERFACE_ENTRY( IPersistStorage
, &IID_IPersist
),
524 INTERFACE_ENTRY( IPersistFile
, &IID_IPersist
),
525 INTERFACE_ENTRY( IDataAdviseHolder
, NULL
),
526 INTERFACE_ENTRY( IOleAdviseHolder
, NULL
),
527 INTERFACE_ENTRY( IOleInPlaceObject
, &IID_IOleWindow
),
528 INTERFACE_ENTRY( IOleInPlaceUIWindow
, &IID_IOleWindow
),
529 INTERFACE_ENTRY( IOleInPlaceActiveObject
, &IID_IOleWindow
),
530 INTERFACE_ENTRY( IOleInPlaceSite
, &IID_IOleWindow
),
531 INTERFACE_ENTRY( IOleContainer
, &IID_IParseDisplayName
),
532 INTERFACE_ENTRY( IOleItemContainer
, &IID_IOleContainer
),
533 INTERFACE_ENTRY( IDropSource
, NULL
),
534 INTERFACE_ENTRY( IAdviseSink2
, &IID_IAdviseSink
),
535 INTERFACE_ENTRY( IViewObject2
, &IID_IViewObject
),
536 INTERFACE_ENTRY( IOleCache2
, &IID_IOleCache
),
537 INTERFACE_ENTRY( IClientSecurity
, NULL
),
538 INTERFACE_ENTRY( IServerSecurity
, NULL
),
539 { NULL
} /* list terminator */
542 /***********************************************************************
543 * DllRegisterServer (OLE32.@)
545 HRESULT WINAPI
DllRegisterServer(void)
551 hr
= OLE32_DllRegisterServer();
553 hr
= register_coclasses(coclass_list
);
555 hr
= register_interfaces(interface_list
);
559 /***********************************************************************
560 * DllUnregisterServer (OLE32.@)
562 HRESULT WINAPI
DllUnregisterServer(void)
568 hr
= unregister_coclasses(coclass_list
);
570 hr
= unregister_interfaces(interface_list
);
572 hr
= OLE32_DllUnregisterServer();