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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "comcat_private.h"
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
, const CATID
*rgcatid
);
45 static HRESULT
COMCAT_UnRegisterClassCategories(
46 REFCLSID rclsid
, LPCWSTR type
,
47 ULONG cCategories
, const CATID
*rgcatid
);
49 /**********************************************************************
50 * COMCAT_ICatRegister_QueryInterface
52 static HRESULT WINAPI
COMCAT_ICatRegister_QueryInterface(
57 ComCatMgrImpl
*This
= (ComCatMgrImpl
*)iface
;
58 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid
));
60 if (ppvObj
== NULL
) return E_POINTER
;
62 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ICatRegister
)) {
64 IUnknown_AddRef(iface
);
68 if (IsEqualGUID(riid
, &IID_ICatInformation
)) {
69 *ppvObj
= &This
->infVtbl
;
70 IUnknown_AddRef(iface
);
77 /**********************************************************************
78 * COMCAT_ICatRegister_AddRef
80 static ULONG WINAPI
COMCAT_ICatRegister_AddRef(LPCATREGISTER iface
)
82 return 2; /* non-heap based object */
85 /**********************************************************************
86 * COMCAT_ICatRegister_Release
88 static ULONG WINAPI
COMCAT_ICatRegister_Release(LPCATREGISTER iface
)
90 return 1; /* non-heap based object */
93 /**********************************************************************
94 * COMCAT_ICatRegister_RegisterCategories
96 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterCategories(
106 if (cCategories
&& rgci
== NULL
)
109 /* Create (or open) the component categories key. */
110 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, comcat_keyname
, 0, NULL
, 0,
111 KEY_READ
| KEY_WRITE
, NULL
, &comcat_key
, NULL
);
112 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
114 for (; cCategories
; --cCategories
, ++rgci
) {
115 static const WCHAR fmt
[] = { '%', 'l', 'X', 0 };
120 /* Create (or open) the key for this category. */
121 if (!StringFromGUID2(&rgci
->catid
, keyname
, 39)) continue;
122 res
= RegCreateKeyExW(comcat_key
, keyname
, 0, NULL
, 0,
123 KEY_READ
| KEY_WRITE
, NULL
, &cat_key
, NULL
);
124 if (res
!= ERROR_SUCCESS
) continue;
126 /* Set the value for this locale's description. */
127 wsprintfW(valname
, fmt
, rgci
->lcid
);
128 RegSetValueExW(cat_key
, valname
, 0, REG_SZ
,
129 (CONST BYTE
*)(rgci
->szDescription
),
130 (lstrlenW(rgci
->szDescription
) + 1) * sizeof(WCHAR
));
132 RegCloseKey(cat_key
);
135 RegCloseKey(comcat_key
);
139 /**********************************************************************
140 * COMCAT_ICatRegister_UnRegisterCategories
142 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterCategories(
152 if (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(
183 return COMCAT_RegisterClassCategories(
184 rclsid
, impl_keyname
, cCategories
, rgcatid
);
187 /**********************************************************************
188 * COMCAT_ICatRegister_UnRegisterClassImplCategories
190 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassImplCategories(
198 return COMCAT_UnRegisterClassCategories(
199 rclsid
, impl_keyname
, cCategories
, rgcatid
);
202 /**********************************************************************
203 * COMCAT_ICatRegister_RegisterClassReqCategories
205 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassReqCategories(
213 return COMCAT_RegisterClassCategories(
214 rclsid
, req_keyname
, cCategories
, rgcatid
);
217 /**********************************************************************
218 * COMCAT_ICatRegister_UnRegisterClassReqCategories
220 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassReqCategories(
228 return COMCAT_UnRegisterClassCategories(
229 rclsid
, req_keyname
, cCategories
, rgcatid
);
232 /**********************************************************************
233 * COMCAT_ICatRegister_Vtbl
235 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
=
237 COMCAT_ICatRegister_QueryInterface
,
238 COMCAT_ICatRegister_AddRef
,
239 COMCAT_ICatRegister_Release
,
240 COMCAT_ICatRegister_RegisterCategories
,
241 COMCAT_ICatRegister_UnRegisterCategories
,
242 COMCAT_ICatRegister_RegisterClassImplCategories
,
243 COMCAT_ICatRegister_UnRegisterClassImplCategories
,
244 COMCAT_ICatRegister_RegisterClassReqCategories
,
245 COMCAT_ICatRegister_UnRegisterClassReqCategories
249 /**********************************************************************
250 * static ComCatMgr instance
252 ComCatMgrImpl COMCAT_ComCatMgr
=
254 &COMCAT_ICatRegister_Vtbl
,
255 &COMCAT_ICatInformation_Vtbl
258 /**********************************************************************
259 * COMCAT_RegisterClassCategories
261 static HRESULT
COMCAT_RegisterClassCategories(
265 const CATID
*rgcatid
)
269 HKEY clsid_key
, class_key
, type_key
;
271 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
273 /* Format the class key name. */
274 res
= StringFromGUID2(rclsid
, keyname
, 39);
275 if (FAILED(res
)) return res
;
277 /* Create (or open) the CLSID key. */
278 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0, NULL
, 0,
279 KEY_READ
| KEY_WRITE
, NULL
, &clsid_key
, NULL
);
280 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
282 /* Create (or open) the class key. */
283 res
= RegCreateKeyExW(clsid_key
, keyname
, 0, NULL
, 0,
284 KEY_READ
| KEY_WRITE
, NULL
, &class_key
, NULL
);
285 if (res
== ERROR_SUCCESS
) {
286 /* Create (or open) the category type key. */
287 res
= RegCreateKeyExW(class_key
, type
, 0, NULL
, 0,
288 KEY_READ
| KEY_WRITE
, NULL
, &type_key
, NULL
);
289 if (res
== ERROR_SUCCESS
) {
290 for (; cCategories
; --cCategories
, ++rgcatid
) {
293 /* Format the category key name. */
294 res
= StringFromGUID2(rgcatid
, keyname
, 39);
295 if (FAILED(res
)) continue;
297 /* Do the register. */
298 res
= RegCreateKeyExW(type_key
, keyname
, 0, NULL
, 0,
299 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
300 if (res
== ERROR_SUCCESS
) RegCloseKey(key
);
304 RegCloseKey(class_key
);
306 RegCloseKey(clsid_key
);
311 /**********************************************************************
312 * COMCAT_UnRegisterClassCategories
314 static HRESULT
COMCAT_UnRegisterClassCategories(
318 const CATID
*rgcatid
)
320 WCHAR keyname
[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
324 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
326 /* Format the class category type key name. */
327 res
= StringFromGUID2(rclsid
, keyname
+ 6, 39);
328 if (FAILED(res
)) return res
;
330 lstrcpyW(keyname
+ 45, type
);
332 /* Open the class category type key. */
333 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, keyname
, 0,
334 KEY_READ
| KEY_WRITE
, &type_key
);
335 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
337 for (; cCategories
; --cCategories
, ++rgcatid
) {
338 /* Format the category key name. */
339 res
= StringFromGUID2(rgcatid
, keyname
, 39);
340 if (FAILED(res
)) continue;
342 /* Do the unregister. */
343 RegDeleteKeyW(type_key
, keyname
);
345 RegCloseKey(type_key
);