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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "comcat_private.h"
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 struct class_categories {
37 static struct class_categories *COMCAT_PrepareClassCategories(
38 ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids);
39 static HRESULT COMCAT_IsClassOfCategories(
40 HKEY key, struct class_categories const* class_categories);
41 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(
42 struct class_categories *class_categories);
43 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
44 REFCLSID rclsid, LPCWSTR impl_req);
46 /**********************************************************************
47 * COMCAT_ICatInformation_QueryInterface
49 static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
50 LPCATINFORMATION iface,
54 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
55 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
57 if (ppvObj == NULL) return E_POINTER;
59 return IUnknown_QueryInterface((LPUNKNOWN)&This->unkVtbl, riid, ppvObj);
62 /**********************************************************************
63 * COMCAT_ICatInformation_AddRef
65 static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
67 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
70 return IUnknown_AddRef((LPUNKNOWN)&This->unkVtbl);
73 /**********************************************************************
74 * COMCAT_ICatInformation_Release
76 static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
78 ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface);
81 return IUnknown_Release((LPUNKNOWN)&This->unkVtbl);
84 /**********************************************************************
85 * COMCAT_ICatInformation_EnumCategories
87 static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
88 LPCATINFORMATION iface,
90 LPENUMCATEGORYINFO *ppenumCatInfo)
92 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
95 if (ppenumCatInfo == NULL) return E_POINTER;
97 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
98 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
99 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
103 /**********************************************************************
104 * COMCAT_ICatInformation_GetCategoryDesc
106 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
107 LPCATINFORMATION iface,
112 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
113 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
114 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
115 'r', 'i', 'e', 's', '\\', 0 };
119 TRACE("\n\tCATID:\t%s\n\tLCID:\t%X\n",debugstr_guid(rcatid), lcid);
121 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
123 /* Open the key for this category. */
124 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
125 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
126 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
128 /* Allocate a sensible amount of memory for the description. */
129 *ppszDesc = (PWCHAR) CoTaskMemAlloc(128 * sizeof(WCHAR));
130 if (*ppszDesc == NULL) {
132 return E_OUTOFMEMORY;
135 /* Get the description, and make sure it's null terminated. */
136 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
139 CoTaskMemFree(*ppszDesc);
146 /**********************************************************************
147 * COMCAT_ICatInformation_EnumClassesOfCategories
149 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
150 LPCATINFORMATION iface,
155 LPENUMCLSID *ppenumCLSID)
157 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
158 struct class_categories *categories;
162 if (cImplemented == (ULONG)-1)
164 if (cRequired == (ULONG)-1)
167 if (ppenumCLSID == NULL ||
168 (cImplemented && rgcatidImpl == NULL) ||
169 (cRequired && rgcatidReq == NULL)) return E_POINTER;
171 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
172 cRequired, rgcatidReq);
173 if (categories == NULL) return E_OUTOFMEMORY;
174 *ppenumCLSID = COMCAT_CLSID_IEnumGUID_Construct(categories);
175 if (*ppenumCLSID == NULL) {
176 HeapFree(GetProcessHeap(), 0, categories);
177 return E_OUTOFMEMORY;
179 IEnumGUID_AddRef(*ppenumCLSID);
183 /**********************************************************************
184 * COMCAT_ICatInformation_IsClassOfCategories
186 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
187 LPCATINFORMATION iface,
194 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
195 WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
197 struct class_categories *categories;
200 if (WINE_TRACE_ON(ole)) {
202 TRACE("\n\tCLSID:\t%s\n\tImplemented %u\n",debugstr_guid(rclsid),cImplemented);
203 for (count = 0; count < cImplemented; ++count)
204 TRACE("\t\t%s\n",debugstr_guid(&rgcatidImpl[count]));
205 TRACE("\tRequired %u\n",cRequired);
206 for (count = 0; count < cRequired; ++count)
207 TRACE("\t\t%s\n",debugstr_guid(&rgcatidReq[count]));
210 if ((cImplemented && rgcatidImpl == NULL) ||
211 (cRequired && rgcatidReq == NULL)) return E_POINTER;
213 res = StringFromGUID2(rclsid, keyname + 6, 39);
214 if (FAILED(res)) return res;
216 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
217 cRequired, rgcatidReq);
218 if (categories == NULL) return E_OUTOFMEMORY;
220 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
221 if (res == ERROR_SUCCESS) {
222 res = COMCAT_IsClassOfCategories(key, categories);
224 } else res = S_FALSE;
226 HeapFree(GetProcessHeap(), 0, categories);
231 /**********************************************************************
232 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
234 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
235 LPCATINFORMATION iface,
237 LPENUMCATID *ppenumCATID)
239 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
240 static const WCHAR postfix[24] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
241 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
242 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
244 TRACE("\n\tCLSID:\t%s\n",debugstr_guid(rclsid));
246 if (rclsid == NULL || ppenumCATID == NULL)
249 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
250 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
254 /**********************************************************************
255 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
257 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
258 LPCATINFORMATION iface,
260 LPENUMCATID *ppenumCATID)
262 /* ICOM_THIS_MULTI(ComCatMgrImpl, infVtbl, iface); */
263 static const WCHAR postfix[21] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
264 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
265 'r', 'i', 'e', 's', 0 };
267 TRACE("\n\tCLSID:\t%s\n",debugstr_guid(rclsid));
269 if (rclsid == NULL || ppenumCATID == NULL)
272 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
273 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
277 /**********************************************************************
278 * COMCAT_ICatInformation_Vtbl
280 const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
282 COMCAT_ICatInformation_QueryInterface,
283 COMCAT_ICatInformation_AddRef,
284 COMCAT_ICatInformation_Release,
285 COMCAT_ICatInformation_EnumCategories,
286 COMCAT_ICatInformation_GetCategoryDesc,
287 COMCAT_ICatInformation_EnumClassesOfCategories,
288 COMCAT_ICatInformation_IsClassOfCategories,
289 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
290 COMCAT_ICatInformation_EnumReqCategoriesOfClass
293 /**********************************************************************
294 * IEnumCATEGORYINFO implementation
296 * This implementation is not thread-safe. The manager itself is, but
297 * I can't imagine a valid use of an enumerator in several threads.
301 const IEnumCATEGORYINFOVtbl *lpVtbl;
306 } IEnumCATEGORYINFOImpl;
308 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
310 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
314 return InterlockedIncrement(&This->ref);
317 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
318 LPENUMCATEGORYINFO iface,
322 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
324 if (ppvObj == NULL) return E_POINTER;
326 if (IsEqualGUID(riid, &IID_IUnknown) ||
327 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
329 *ppvObj = (LPVOID)iface;
330 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
334 return E_NOINTERFACE;
337 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
339 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
344 ref = InterlockedDecrement(&This->ref);
346 if (This->key) RegCloseKey(This->key);
347 HeapFree(GetProcessHeap(), 0, This);
353 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
354 LPENUMCATEGORYINFO iface,
359 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
364 if (rgelt == NULL) return E_POINTER;
366 if (This->key) while (fetched < celt) {
373 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
374 NULL, NULL, NULL, NULL);
375 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
376 ++(This->next_index);
378 hr = CLSIDFromString(catid, &rgelt->catid);
379 if (FAILED(hr)) continue;
381 res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
382 if (res != ERROR_SUCCESS) continue;
384 hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
385 rgelt->szDescription, 128);
387 if (FAILED(hr)) continue;
389 rgelt->lcid = This->lcid;
394 if (pceltFetched) *pceltFetched = fetched;
395 return fetched == celt ? S_OK : S_FALSE;
398 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
399 LPENUMCATEGORYINFO iface,
402 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
406 This->next_index += celt;
407 /* This should return S_FALSE when there aren't celt elems to skip. */
411 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(LPENUMCATEGORYINFO iface)
413 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
417 This->next_index = 0;
421 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
422 LPENUMCATEGORYINFO iface,
423 IEnumCATEGORYINFO **ppenum)
425 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
426 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
427 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
428 'r', 'i', 'e', 's', 0 };
429 IEnumCATEGORYINFOImpl *new_this;
433 if (ppenum == NULL) return E_POINTER;
435 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
436 if (new_this == NULL) return E_OUTOFMEMORY;
438 new_this->lpVtbl = This->lpVtbl;
440 new_this->lcid = This->lcid;
441 /* FIXME: could we more efficiently use DuplicateHandle? */
442 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
443 new_this->next_index = This->next_index;
445 *ppenum = (LPENUMCATEGORYINFO)new_this;
449 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
451 COMCAT_IEnumCATEGORYINFO_QueryInterface,
452 COMCAT_IEnumCATEGORYINFO_AddRef,
453 COMCAT_IEnumCATEGORYINFO_Release,
454 COMCAT_IEnumCATEGORYINFO_Next,
455 COMCAT_IEnumCATEGORYINFO_Skip,
456 COMCAT_IEnumCATEGORYINFO_Reset,
457 COMCAT_IEnumCATEGORYINFO_Clone
460 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
462 IEnumCATEGORYINFOImpl *This;
464 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
466 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
467 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
468 'r', 'i', 'e', 's', 0 };
470 This->lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
472 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
474 return (LPENUMCATEGORYINFO)This;
477 /**********************************************************************
478 * COMCAT_GetCategoryDesc
480 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
483 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
486 DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);
488 if (pszDesc == NULL) return E_INVALIDARG;
490 /* FIXME: lcid comparisons are more complex than this! */
491 wsprintfW(valname, fmt, lcid);
492 res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
493 if (res != ERROR_SUCCESS || type != REG_SZ) {
494 FIXME("Simplified lcid comparison\n");
495 return CAT_E_NODESCRIPTION;
497 pszDesc[size / sizeof(WCHAR)] = (WCHAR)0;
502 /**********************************************************************
503 * COMCAT_PrepareClassCategories
505 static struct class_categories *COMCAT_PrepareClassCategories(
506 ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids)
508 struct class_categories *categories;
511 categories = HeapAlloc(
512 GetProcessHeap(), HEAP_ZERO_MEMORY,
513 sizeof(struct class_categories) +
514 ((impl_count + req_count) * 39 + 2) * sizeof(WCHAR));
515 if (categories == NULL) return categories;
517 strings = (WCHAR *)(categories + 1);
518 categories->impl_strings = strings;
519 while (impl_count--) {
520 StringFromGUID2(impl_catids++, strings, 39);
525 categories->req_strings = strings;
526 while (req_count--) {
527 StringFromGUID2(req_catids++, strings, 39);
535 /**********************************************************************
536 * COMCAT_IsClassOfCategories
538 static HRESULT COMCAT_IsClassOfCategories(
540 struct class_categories const* categories)
542 static const WCHAR impl_keyname[] = { 'I', 'm', 'p', 'l', 'e', 'm', 'e', 'n',
543 't', 'e', 'd', ' ', 'C', 'a', 't', 'e',
544 'g', 'o', 'r', 'i', 'e', 's', 0 };
545 static const WCHAR req_keyname[] = { 'R', 'e', 'q', 'u', 'i', 'r', 'e', 'd',
546 ' ', 'C', 'a', 't', 'e', 'g', 'o', 'r',
553 /* Check that every given category is implemented by class. */
554 res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
555 if (res != ERROR_SUCCESS) return S_FALSE;
556 for (string = categories->impl_strings; *string; string += 39) {
558 res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
559 if (res != ERROR_SUCCESS) {
567 /* Check that all categories required by class are given. */
568 res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
569 if (res == ERROR_SUCCESS) {
570 for (index = 0; ; ++index) {
574 res = RegEnumKeyExW(subkey, index, keyname, &size,
575 NULL, NULL, NULL, NULL);
576 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
577 if (size != 38) continue; /* bogus catid in registry */
578 for (string = categories->req_strings; *string; string += 39)
579 if (!strcmpiW(string, keyname)) break;
591 /**********************************************************************
592 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
594 * This implementation is not thread-safe. The manager itself is, but
595 * I can't imagine a valid use of an enumerator in several threads.
599 const IEnumGUIDVtbl *lpVtbl;
601 struct class_categories *categories;
604 } CLSID_IEnumGUIDImpl;
606 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
608 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
611 return InterlockedIncrement(&This->ref);
614 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
619 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
621 if (ppvObj == NULL) return E_POINTER;
623 if (IsEqualGUID(riid, &IID_IUnknown) ||
624 IsEqualGUID(riid, &IID_IEnumGUID))
626 *ppvObj = (LPVOID)iface;
627 COMCAT_CLSID_IEnumGUID_AddRef(iface);
631 return E_NOINTERFACE;
634 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
636 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
641 ref = InterlockedDecrement(&This->ref);
643 if (This->key) RegCloseKey(This->key);
644 HeapFree(GetProcessHeap(), 0, (LPVOID)This->categories);
645 HeapFree(GetProcessHeap(), 0, This);
651 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
657 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
662 if (rgelt == NULL) return E_POINTER;
664 if (This->key) while (fetched < celt) {
671 res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
672 NULL, NULL, NULL, NULL);
673 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
674 ++(This->next_index);
676 hr = CLSIDFromString(clsid, rgelt);
677 if (FAILED(hr)) continue;
679 res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
680 if (res != ERROR_SUCCESS) continue;
682 hr = COMCAT_IsClassOfCategories(subkey, This->categories);
684 if (hr != S_OK) continue;
690 if (pceltFetched) *pceltFetched = fetched;
691 return fetched == celt ? S_OK : S_FALSE;
694 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Skip(
698 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
702 This->next_index += celt;
703 FIXME("Never returns S_FALSE\n");
707 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface)
709 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
713 This->next_index = 0;
717 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
721 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
722 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
723 CLSID_IEnumGUIDImpl *new_this;
728 if (ppenum == NULL) return E_POINTER;
730 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
731 if (new_this == NULL) return E_OUTOFMEMORY;
733 new_this->lpVtbl = This->lpVtbl;
735 size = HeapSize(GetProcessHeap(), 0, (LPVOID)This->categories);
736 new_this->categories =
737 HeapAlloc(GetProcessHeap(), 0, size);
738 if (new_this->categories == NULL) {
739 HeapFree(GetProcessHeap(), 0, new_this);
740 return E_OUTOFMEMORY;
742 memcpy((LPVOID)new_this->categories, This->categories, size);
743 /* FIXME: could we more efficiently use DuplicateHandle? */
744 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
745 new_this->next_index = This->next_index;
747 *ppenum = (LPENUMGUID)new_this;
751 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl =
753 COMCAT_CLSID_IEnumGUID_QueryInterface,
754 COMCAT_CLSID_IEnumGUID_AddRef,
755 COMCAT_CLSID_IEnumGUID_Release,
756 COMCAT_CLSID_IEnumGUID_Next,
757 COMCAT_CLSID_IEnumGUID_Skip,
758 COMCAT_CLSID_IEnumGUID_Reset,
759 COMCAT_CLSID_IEnumGUID_Clone
762 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *categories)
764 CLSID_IEnumGUIDImpl *This;
766 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
768 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
770 This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
771 This->categories = categories;
772 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
774 return (LPENUMGUID)This;
777 /**********************************************************************
778 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
780 * This implementation is not thread-safe. The manager itself is, but
781 * I can't imagine a valid use of an enumerator in several threads.
785 const IEnumGUIDVtbl *lpVtbl;
790 } CATID_IEnumGUIDImpl;
792 static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
794 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
797 return InterlockedIncrement(&This->ref);
800 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
805 TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
807 if (ppvObj == NULL) return E_POINTER;
809 if (IsEqualGUID(riid, &IID_IUnknown) ||
810 IsEqualGUID(riid, &IID_IEnumGUID))
812 *ppvObj = (LPVOID)iface;
813 COMCAT_CATID_IEnumGUID_AddRef(iface);
817 return E_NOINTERFACE;
820 static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
822 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
827 ref = InterlockedDecrement(&This->ref);
829 if (This->key) RegCloseKey(This->key);
830 HeapFree(GetProcessHeap(), 0, This);
836 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
842 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
847 if (rgelt == NULL) return E_POINTER;
849 if (This->key) while (fetched < celt) {
855 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
856 NULL, NULL, NULL, NULL);
857 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
858 ++(This->next_index);
860 hr = CLSIDFromString(catid, rgelt);
861 if (FAILED(hr)) continue;
867 if (pceltFetched) *pceltFetched = fetched;
868 return fetched == celt ? S_OK : S_FALSE;
871 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Skip(
875 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
879 This->next_index += celt;
880 FIXME("Never returns S_FALSE\n");
884 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface)
886 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
890 This->next_index = 0;
894 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
898 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
899 CATID_IEnumGUIDImpl *new_this;
903 if (ppenum == NULL) return E_POINTER;
905 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
906 if (new_this == NULL) return E_OUTOFMEMORY;
908 new_this->lpVtbl = This->lpVtbl;
910 lstrcpyW(new_this->keyname, This->keyname);
911 /* FIXME: could we more efficiently use DuplicateHandle? */
912 RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
913 new_this->next_index = This->next_index;
915 *ppenum = (LPENUMGUID)new_this;
919 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl =
921 COMCAT_CATID_IEnumGUID_QueryInterface,
922 COMCAT_CATID_IEnumGUID_AddRef,
923 COMCAT_CATID_IEnumGUID_Release,
924 COMCAT_CATID_IEnumGUID_Next,
925 COMCAT_CATID_IEnumGUID_Skip,
926 COMCAT_CATID_IEnumGUID_Reset,
927 COMCAT_CATID_IEnumGUID_Clone
930 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
931 REFCLSID rclsid, LPCWSTR postfix)
933 CATID_IEnumGUIDImpl *This;
935 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
937 WCHAR prefix[6] = { 'C', 'L', 'S', 'I', 'D', '\\' };
939 This->lpVtbl = &COMCAT_CATID_IEnumGUID_Vtbl;
940 memcpy(This->keyname, prefix, sizeof(prefix));
941 StringFromGUID2(rclsid, This->keyname + 6, 39);
942 lstrcpyW(This->keyname + 44, postfix);
943 RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
945 return (LPENUMGUID)This;