2 * ComCatMgr ICatInformation 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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(ole);
28 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid);
29 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
32 /**********************************************************************
33 * COMCAT_ICatInformation_QueryInterface
35 static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
36 LPCATINFORMATION iface,
40 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
41 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
43 if (This == NULL || ppvObj == NULL) return E_POINTER;
45 return IUnknown_QueryInterface((LPUNKNOWN)&This->unkVtbl, riid, ppvObj);
48 /**********************************************************************
49 * COMCAT_ICatInformation_AddRef
51 static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
53 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
56 if (This == NULL) return E_POINTER;
58 return IUnknown_AddRef((LPUNKNOWN)&This->unkVtbl);
61 /**********************************************************************
62 * COMCAT_ICatInformation_Release
64 static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
66 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
69 if (This == NULL) return E_POINTER;
71 return IUnknown_Release((LPUNKNOWN)&This->unkVtbl);
74 /**********************************************************************
75 * COMCAT_ICatInformation_EnumCategories
77 static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
78 LPCATINFORMATION iface,
80 LPENUMCATEGORYINFO *ppenumCatInfo)
82 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
85 if (iface == NULL || ppenumCatInfo == NULL) return E_POINTER;
87 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
88 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
89 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
93 /**********************************************************************
94 * COMCAT_ICatInformation_GetCategoryDesc
96 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
97 LPCATINFORMATION iface,
102 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
103 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
104 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
105 'r', 'i', 'e', 's', '\\', 0 };
109 TRACE("\n\tCATID:\t%s\n\tLCID:\t%lX\n",debugstr_guid(rcatid), lcid);
111 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
113 /* Open the key for this category. */
114 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
115 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
116 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
118 /* Allocate a sensible amount of memory for the description. */
119 *ppszDesc = (PWCHAR) CoTaskMemAlloc(128 * sizeof(WCHAR));
120 if (*ppszDesc == NULL) {
122 return E_OUTOFMEMORY;
125 /* Get the description, and make sure it's null terminated. */
126 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
129 CoTaskMemFree(*ppszDesc);
136 /**********************************************************************
137 * COMCAT_ICatInformation_EnumClassesOfCategories
139 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
140 LPCATINFORMATION iface,
145 LPENUMCLSID *ppenumCLSID)
147 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
153 /**********************************************************************
154 * COMCAT_ICatInformation_IsClassOfCategories
156 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
157 LPCATINFORMATION iface,
164 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
170 /**********************************************************************
171 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
173 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
174 LPCATINFORMATION iface,
176 LPENUMCATID *ppenumCATID)
178 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
184 /**********************************************************************
185 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
187 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
188 LPCATINFORMATION iface,
190 LPENUMCATID *ppenumCATID)
192 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
198 /**********************************************************************
199 * COMCAT_ICatInformation_Vtbl
201 ICOM_VTABLE(ICatInformation) COMCAT_ICatInformation_Vtbl =
203 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
204 COMCAT_ICatInformation_QueryInterface,
205 COMCAT_ICatInformation_AddRef,
206 COMCAT_ICatInformation_Release,
207 COMCAT_ICatInformation_EnumCategories,
208 COMCAT_ICatInformation_GetCategoryDesc,
209 COMCAT_ICatInformation_EnumClassesOfCategories,
210 COMCAT_ICatInformation_IsClassOfCategories,
211 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
212 COMCAT_ICatInformation_EnumReqCategoriesOfClass
215 /**********************************************************************
216 * IEnumCATEGORYINFO implementation
218 * This implementation is not thread-safe. The manager itself is, but
219 * I can't imagine a valid use of an enumerator in several threads.
223 ICOM_VFIELD(IEnumCATEGORYINFO);
228 } IEnumCATEGORYINFOImpl;
230 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
232 ICOM_THIS(IEnumCATEGORYINFOImpl, iface);
235 if (This == NULL) return E_POINTER;
237 return ++(This->ref);
240 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
241 LPENUMCATEGORYINFO iface,
245 ICOM_THIS(IEnumCATEGORYINFOImpl, iface);
246 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
248 if (This == NULL || ppvObj == NULL) return E_POINTER;
250 if (IsEqualGUID(riid, &IID_IUnknown) ||
251 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
253 *ppvObj = (LPVOID)iface;
254 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
258 return E_NOINTERFACE;
261 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
263 ICOM_THIS(IEnumCATEGORYINFOImpl, iface);
266 if (This == NULL) return E_POINTER;
268 if (--(This->ref) == 0) {
269 if (This->key) RegCloseKey(This->key);
270 HeapFree(GetProcessHeap(), 0, This);
276 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
277 LPENUMCATEGORYINFO iface,
282 ICOM_THIS(IEnumCATEGORYINFOImpl, iface);
287 if (This == NULL || rgelt == NULL) return E_POINTER;
289 if (This->key) while (fetched < celt) {
295 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
296 NULL, NULL, NULL, NULL);
297 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
298 ++(This->next_index);
300 res = CLSIDFromString(catid, &rgelt->catid);
301 if (FAILED(res)) continue;
303 res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
304 if (res != ERROR_SUCCESS) continue;
306 res = COMCAT_GetCategoryDesc(subkey, This->lcid,
307 rgelt->szDescription, 128);
309 if (FAILED(res)) continue;
311 rgelt->lcid = This->lcid;
316 if (pceltFetched) *pceltFetched = fetched;
317 return fetched == celt ? S_OK : S_FALSE;
320 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
321 LPENUMCATEGORYINFO iface,
324 /* ICOM_THIS(IEnumCATEGORYINFOImpl, iface); */
330 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(LPENUMCATEGORYINFO iface)
332 /* ICOM_THIS(IEnumCATEGORYINFOImpl, iface); */
338 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
339 LPENUMCATEGORYINFO iface,
340 IEnumCATEGORYINFO **ppenum)
342 /* ICOM_THIS(IEnumCATEGORYINFOImpl, iface); */
348 ICOM_VTABLE(IEnumCATEGORYINFO) COMCAT_IEnumCATEGORYINFO_Vtbl =
350 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
351 COMCAT_IEnumCATEGORYINFO_QueryInterface,
352 COMCAT_IEnumCATEGORYINFO_AddRef,
353 COMCAT_IEnumCATEGORYINFO_Release,
354 COMCAT_IEnumCATEGORYINFO_Next,
355 COMCAT_IEnumCATEGORYINFO_Skip,
356 COMCAT_IEnumCATEGORYINFO_Reset,
357 COMCAT_IEnumCATEGORYINFO_Clone
360 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
362 IEnumCATEGORYINFOImpl *This;
364 This = (IEnumCATEGORYINFOImpl *) HeapAlloc(
365 GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
367 WCHAR keyname[21] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
368 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
369 'r', 'i', 'e', 's', 0 };
371 ICOM_VTBL(This) = &COMCAT_IEnumCATEGORYINFO_Vtbl;
373 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
375 return (LPENUMCATEGORYINFO)This;
378 /**********************************************************************
379 * COMCAT_GetCategoryDesc
381 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
384 WCHAR fmt[4] = { '%', 'l', 'X', 0 };
387 DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);
389 if (pszDesc == NULL) return E_INVALIDARG;
391 /* FIXME: lcid comparisons are more complex than this! */
392 swprintf(valname, fmt, lcid);
393 res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
394 if (res != ERROR_SUCCESS || type != REG_SZ) return CAT_E_NODESCRIPTION;
395 pszDesc[size / sizeof(WCHAR)] = (WCHAR)0;