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 static GUID const CLSID_PSFactoryBuffer_actxprxy = {
412 0xB8DA6310, 0xE19B, 0x11D0, {0x93,0x3C,0x00,0xA0,0xC9,0x0D,0xCA,0xA9} };
414 extern GUID const CLSID_Picture_Metafile;
415 extern GUID const CLSID_Picture_Dib;
417 static struct regsvr_coclass const coclass_list[] = {
424 { &CLSID_FileMoniker,
431 { &CLSID_ItemMoniker,
437 { &CLSID_AntiMoniker,
443 { &CLSID_PointerMoniker,
449 { &CLSID_PackagerMoniker,
455 { &CLSID_CompositeMoniker,
467 { &CLSID_Picture_Metafile,
468 "Picture (Metafile)",
474 { &CLSID_Picture_Dib,
475 "Picture (Device Independent Bitmap)",
481 { &CLSID_ClassMoniker,
488 { &CLSID_PSFactoryBuffer,
494 { &CLSID_StdGlobalInterfaceTable,
495 "StdGlobalInterfaceTable",
500 { &CLSID_StdComponentCategoriesMgr,
501 "Component Categories Manager",
506 { NULL } /* list terminator */
509 /***********************************************************************
513 #define INTERFACE_ENTRY(interface, base, clsid32) { &IID_##interface, #interface, base, sizeof(interface##Vtbl)/sizeof(void*), NULL, clsid32 }
514 #define BAS_INTERFACE_ENTRY(interface, base) INTERFACE_ENTRY(interface, &IID_##base, NULL)
515 #define ACTX_INTERFACE_ENTRY(interface) INTERFACE_ENTRY(interface, NULL, &CLSID_PSFactoryBuffer_actxprxy)
516 #define LCL_INTERFACE_ENTRY(interface) INTERFACE_ENTRY(interface, NULL, NULL)
518 static const struct regsvr_interface interface_list[] = {
519 LCL_INTERFACE_ENTRY(IUnknown),
520 LCL_INTERFACE_ENTRY(IMalloc),
521 LCL_INTERFACE_ENTRY(IMarshal),
522 BAS_INTERFACE_ENTRY(IMoniker, IPersistStream),
523 LCL_INTERFACE_ENTRY(IMessageFilter),
524 LCL_INTERFACE_ENTRY(IStdMarshalInfo),
525 LCL_INTERFACE_ENTRY(IExternalConnection),
526 LCL_INTERFACE_ENTRY(IMallocSpy),
527 LCL_INTERFACE_ENTRY(IMultiQI),
528 BAS_INTERFACE_ENTRY(IPersistStream, IPersist),
529 BAS_INTERFACE_ENTRY(IPersistStorage, IPersist),
530 BAS_INTERFACE_ENTRY(IPersistFile, IPersist),
531 LCL_INTERFACE_ENTRY(IDataAdviseHolder),
532 LCL_INTERFACE_ENTRY(IOleAdviseHolder),
533 BAS_INTERFACE_ENTRY(IOleInPlaceObject, IOleWindow),
534 BAS_INTERFACE_ENTRY(IOleInPlaceUIWindow, IOleWindow),
535 BAS_INTERFACE_ENTRY(IOleInPlaceActiveObject, IOleWindow),
536 BAS_INTERFACE_ENTRY(IOleInPlaceSite, IOleWindow),
537 BAS_INTERFACE_ENTRY(IOleContainer, IParseDisplayName),
538 BAS_INTERFACE_ENTRY(IOleItemContainer, IOleContainer),
539 LCL_INTERFACE_ENTRY(IDropSource),
540 BAS_INTERFACE_ENTRY(IAdviseSink2, IAdviseSink),
541 BAS_INTERFACE_ENTRY(IViewObject2, IViewObject),
542 BAS_INTERFACE_ENTRY(IOleCache2, IOleCache),
543 LCL_INTERFACE_ENTRY(IClientSecurity),
544 LCL_INTERFACE_ENTRY(IServerSecurity),
545 ACTX_INTERFACE_ENTRY(IEnumGUID),
546 ACTX_INTERFACE_ENTRY(IEnumCATEGORYINFO),
547 ACTX_INTERFACE_ENTRY(ICatRegister),
548 ACTX_INTERFACE_ENTRY(ICatInformation),
549 { NULL } /* list terminator */
552 /***********************************************************************
553 * DllRegisterServer (OLE32.@)
555 HRESULT WINAPI DllRegisterServer(void)
561 hr = OLE32_DllRegisterServer();
563 hr = register_coclasses(coclass_list);
565 hr = register_interfaces(interface_list);
569 /***********************************************************************
570 * DllUnregisterServer (OLE32.@)
572 HRESULT WINAPI DllUnregisterServer(void)
578 hr = unregister_coclasses(coclass_list);
580 hr = unregister_interfaces(interface_list);
582 hr = OLE32_DllUnregisterServer();