2 * ComCatMgr ICatRegister implementation for comcat.dll
4 * Copyright (C) 2002 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
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
27 /**********************************************************************
28 * File-scope string constants
30 static const WCHAR comcat_keyname
[21] = {
31 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n', 't', ' ', 'C', 'a',
32 't', 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
33 static const WCHAR impl_keyname
[23] = {
34 'I', 'm', 'p', 'l', 'e', 'm', 'e', 'n',
35 't', 'e', 'd', ' ', 'C', 'a', 't', 'e',
36 'g', 'o', 'r', 'i', 'e', 's', 0 };
37 static const WCHAR req_keyname
[20] = {
38 'R', 'e', 'q', 'u', 'i', 'r', 'e', 'd',
39 ' ', 'C', 'a', 't', 'e', 'g', 'o', 'r',
42 static HRESULT
COMCAT_RegisterClassCategories(
43 REFCLSID rclsid
, LPCWSTR type
,
44 ULONG cCategories
, CATID
*rgcatid
);
45 static HRESULT
COMCAT_UnRegisterClassCategories(
46 REFCLSID rclsid
, LPCWSTR type
,
47 ULONG cCategories
, CATID
*rgcatid
);
49 /**********************************************************************
50 * COMCAT_ICatRegister_QueryInterface
52 static HRESULT WINAPI
COMCAT_ICatRegister_QueryInterface(
57 ICOM_THIS_MULTI(ComCatMgrImpl
, regVtbl
, iface
);
58 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
60 if (This
== NULL
|| ppvObj
== NULL
) return E_POINTER
;
62 return IUnknown_QueryInterface((LPUNKNOWN
)&This
->unkVtbl
, riid
, ppvObj
);
65 /**********************************************************************
66 * COMCAT_ICatRegister_AddRef
68 static ULONG WINAPI
COMCAT_ICatRegister_AddRef(LPCATREGISTER iface
)
70 ICOM_THIS_MULTI(ComCatMgrImpl
, regVtbl
, iface
);
73 if (This
== NULL
) return E_POINTER
;
75 return IUnknown_AddRef((LPUNKNOWN
)&This
->unkVtbl
);
78 /**********************************************************************
79 * COMCAT_ICatRegister_Release
81 static ULONG WINAPI
COMCAT_ICatRegister_Release(LPCATREGISTER iface
)
83 ICOM_THIS_MULTI(ComCatMgrImpl
, regVtbl
, iface
);
86 if (This
== NULL
) return E_POINTER
;
88 return IUnknown_Release((LPUNKNOWN
)&This
->unkVtbl
);
91 /**********************************************************************
92 * COMCAT_ICatRegister_RegisterCategories
94 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterCategories(
99 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
105 if (iface
== NULL
|| (cCategories
&& rgci
== NULL
))
108 /* Create (or open) the component categories key. */
109 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, comcat_keyname
, 0, NULL
, 0,
110 KEY_READ
| KEY_WRITE
, NULL
, &comcat_key
, NULL
);
111 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
113 for (; cCategories
; --cCategories
, ++rgci
) {
114 WCHAR fmt
[4] = { '%', 'l', 'X', 0 };
119 /* Create (or open) the key for this category. */
120 if (!StringFromGUID2(&rgci
->catid
, keyname
, 39)) continue;
121 res
= RegCreateKeyExW(comcat_key
, keyname
, 0, NULL
, 0,
122 KEY_READ
| KEY_WRITE
, NULL
, &cat_key
, NULL
);
123 if (res
!= ERROR_SUCCESS
) continue;
125 /* Set the value for this locale's description. */
126 wsprintfW(valname
, fmt
, rgci
->lcid
);
127 RegSetValueExW(cat_key
, valname
, 0, REG_SZ
,
128 (CONST BYTE
*)(rgci
->szDescription
),
129 (lstrlenW(rgci
->szDescription
) + 1) * sizeof(WCHAR
));
131 RegCloseKey(cat_key
);
134 RegCloseKey(comcat_key
);
138 /**********************************************************************
139 * COMCAT_ICatRegister_UnRegisterCategories
141 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterCategories(
146 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
152 if (iface
== NULL
|| (cCategories
&& rgcatid
== NULL
))
155 /* Open the component categories key. */
156 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, comcat_keyname
, 0,
157 KEY_READ
| KEY_WRITE
, &comcat_key
);
158 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
160 for (; cCategories
; --cCategories
, ++rgcatid
) {
163 /* Delete the key for this category. */
164 if (!StringFromGUID2(rgcatid
, keyname
, 39)) continue;
165 RegDeleteKeyW(comcat_key
, keyname
);
168 RegCloseKey(comcat_key
);
172 /**********************************************************************
173 * COMCAT_ICatRegister_RegisterClassImplCategories
175 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassImplCategories(
181 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
184 return COMCAT_RegisterClassCategories(
185 rclsid
, impl_keyname
, cCategories
, rgcatid
);
188 /**********************************************************************
189 * COMCAT_ICatRegister_UnRegisterClassImplCategories
191 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassImplCategories(
197 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
200 return COMCAT_UnRegisterClassCategories(
201 rclsid
, impl_keyname
, cCategories
, rgcatid
);
204 /**********************************************************************
205 * COMCAT_ICatRegister_RegisterClassReqCategories
207 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassReqCategories(
213 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
216 return COMCAT_RegisterClassCategories(
217 rclsid
, req_keyname
, cCategories
, rgcatid
);
220 /**********************************************************************
221 * COMCAT_ICatRegister_UnRegisterClassReqCategories
223 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassReqCategories(
229 /* ICOM_THIS_MULTI(ComCatMgrImpl, regVtbl, iface); */
232 return COMCAT_UnRegisterClassCategories(
233 rclsid
, req_keyname
, cCategories
, rgcatid
);
236 /**********************************************************************
237 * COMCAT_ICatRegister_Vtbl
239 ICOM_VTABLE(ICatRegister
) COMCAT_ICatRegister_Vtbl
=
241 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
242 COMCAT_ICatRegister_QueryInterface
,
243 COMCAT_ICatRegister_AddRef
,
244 COMCAT_ICatRegister_Release
,
245 COMCAT_ICatRegister_RegisterCategories
,
246 COMCAT_ICatRegister_UnRegisterCategories
,
247 COMCAT_ICatRegister_RegisterClassImplCategories
,
248 COMCAT_ICatRegister_UnRegisterClassImplCategories
,
249 COMCAT_ICatRegister_RegisterClassReqCategories
,
250 COMCAT_ICatRegister_UnRegisterClassReqCategories
253 /**********************************************************************
254 * COMCAT_RegisterClassCategories
256 static HRESULT
COMCAT_RegisterClassCategories(
264 HKEY clsid_key
, class_key
, type_key
;
266 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
268 /* Format the class key name. */
269 res
= StringFromGUID2(rclsid
, keyname
, 39);
270 if (FAILED(res
)) return res
;
272 /* Create (or open) the CLSID key. */
273 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0, NULL
, 0,
274 KEY_READ
| KEY_WRITE
, NULL
, &clsid_key
, NULL
);
275 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
277 /* Create (or open) the class key. */
278 res
= RegCreateKeyExW(clsid_key
, keyname
, 0, NULL
, 0,
279 KEY_READ
| KEY_WRITE
, NULL
, &class_key
, NULL
);
280 if (res
== ERROR_SUCCESS
) {
281 /* Create (or open) the category type key. */
282 res
= RegCreateKeyExW(class_key
, type
, 0, NULL
, 0,
283 KEY_READ
| KEY_WRITE
, NULL
, &type_key
, NULL
);
284 if (res
== ERROR_SUCCESS
) {
285 for (; cCategories
; --cCategories
, ++rgcatid
) {
288 /* Format the category key name. */
289 res
= StringFromGUID2(rgcatid
, keyname
, 39);
290 if (FAILED(res
)) continue;
292 /* Do the register. */
293 res
= RegCreateKeyExW(type_key
, keyname
, 0, NULL
, 0,
294 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
295 if (res
== ERROR_SUCCESS
) RegCloseKey(key
);
299 RegCloseKey(class_key
);
301 RegCloseKey(clsid_key
);
306 /**********************************************************************
307 * COMCAT_UnRegisterClassCategories
309 static HRESULT
COMCAT_UnRegisterClassCategories(
315 WCHAR keyname
[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
319 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
321 /* Format the class category type key name. */
322 res
= StringFromGUID2(rclsid
, keyname
+ 6, 39);
323 if (FAILED(res
)) return res
;
325 lstrcpyW(keyname
+ 45, type
);
327 /* Open the class category type key. */
328 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, keyname
, 0,
329 KEY_READ
| KEY_WRITE
, &type_key
);
330 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
332 for (; cCategories
; --cCategories
, ++rgcatid
) {
333 /* Format the category key name. */
334 res
= StringFromGUID2(rgcatid
, keyname
, 39);
335 if (FAILED(res
)) continue;
337 /* Do the unregister. */
338 RegDeleteKeyW(type_key
, keyname
);
340 RegCloseKey(type_key
);