2 * Comcat implementation
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
34 #include "compobj_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl;
42 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl;
46 ICatRegister ICatRegister_iface;
47 ICatInformation ICatInformation_iface;
50 /* static ComCatMgr instance */
51 static ComCatMgrImpl COMCAT_ComCatMgr =
53 { &COMCAT_ICatRegister_Vtbl },
54 { &COMCAT_ICatInformation_Vtbl }
57 struct class_categories {
62 static IEnumCATEGORYINFO *COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid);
63 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *class_categories);
64 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(REFCLSID rclsid, LPCWSTR impl_req);
66 /**********************************************************************
67 * File-scope string constants
69 static const WCHAR comcat_keyname[] = {
70 'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0 };
71 static const WCHAR impl_keyname[] = {
72 'I','m','p','l','e','m','e','n','t','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
73 static const WCHAR req_keyname[] = {
74 'R','e','q','u','i','r','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
75 static const WCHAR clsid_keyname[] = { 'C','L','S','I','D',0 };
78 /**********************************************************************
79 * COMCAT_RegisterClassCategories
81 static HRESULT COMCAT_RegisterClassCategories(
89 HKEY clsid_key, class_key, type_key;
91 if (cCategories && rgcatid == NULL) return E_POINTER;
93 /* Format the class key name. */
94 res = StringFromGUID2(rclsid, keyname, 39);
95 if (FAILED(res)) return res;
97 /* Create (or open) the CLSID key. */
98 res = create_classes_key(HKEY_CLASSES_ROOT, clsid_keyname, KEY_READ|KEY_WRITE, &clsid_key);
99 if (res != ERROR_SUCCESS) return E_FAIL;
101 /* Create (or open) the class key. */
102 res = create_classes_key(clsid_key, keyname, KEY_READ|KEY_WRITE, &class_key);
103 if (res == ERROR_SUCCESS) {
104 /* Create (or open) the category type key. */
105 res = create_classes_key(class_key, type, KEY_READ|KEY_WRITE, &type_key);
106 if (res == ERROR_SUCCESS) {
107 for (; cCategories; --cCategories, ++rgcatid) {
110 /* Format the category key name. */
111 res = StringFromGUID2(rgcatid, keyname, 39);
112 if (FAILED(res)) continue;
114 /* Do the register. */
115 res = create_classes_key(type_key, keyname, KEY_READ|KEY_WRITE, &key);
116 if (res == ERROR_SUCCESS) RegCloseKey(key);
120 RegCloseKey(class_key);
122 RegCloseKey(clsid_key);
127 /**********************************************************************
128 * COMCAT_UnRegisterClassCategories
130 static HRESULT COMCAT_UnRegisterClassCategories(
134 const CATID *rgcatid)
136 WCHAR keyname[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
140 if (cCategories && rgcatid == NULL) return E_POINTER;
142 /* Format the class category type key name. */
143 res = StringFromGUID2(rclsid, keyname + 6, 39);
144 if (FAILED(res)) return res;
146 lstrcpyW(keyname + 45, type);
148 /* Open the class category type key. */
149 res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ|KEY_WRITE, &type_key);
150 if (res != ERROR_SUCCESS) return E_FAIL;
152 for (; cCategories; --cCategories, ++rgcatid) {
153 /* Format the category key name. */
154 res = StringFromGUID2(rgcatid, keyname, 39);
155 if (FAILED(res)) continue;
157 /* Do the unregister. */
158 RegDeleteKeyW(type_key, keyname);
160 RegCloseKey(type_key);
165 /**********************************************************************
166 * COMCAT_GetCategoryDesc
168 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
171 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
174 DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);
176 if (pszDesc == NULL) return E_INVALIDARG;
178 /* FIXME: lcid comparisons are more complex than this! */
179 wsprintfW(valname, fmt, lcid);
180 res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
181 if (res != ERROR_SUCCESS || type != REG_SZ) {
182 FIXME("Simplified lcid comparison\n");
183 return CAT_E_NODESCRIPTION;
185 pszDesc[size / sizeof(WCHAR)] = 0;
190 /**********************************************************************
191 * COMCAT_PrepareClassCategories
193 static struct class_categories *COMCAT_PrepareClassCategories(
194 ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids)
196 struct class_categories *categories;
199 categories = HeapAlloc(
200 GetProcessHeap(), HEAP_ZERO_MEMORY,
201 sizeof(struct class_categories) +
202 ((impl_count + req_count) * 39 + 2) * sizeof(WCHAR));
203 if (categories == NULL) return categories;
205 strings = (WCHAR *)(categories + 1);
206 categories->impl_strings = strings;
207 while (impl_count--) {
208 StringFromGUID2(impl_catids++, strings, 39);
213 categories->req_strings = strings;
214 while (req_count--) {
215 StringFromGUID2(req_catids++, strings, 39);
223 /**********************************************************************
224 * COMCAT_IsClassOfCategories
226 static HRESULT COMCAT_IsClassOfCategories(
228 struct class_categories const* categories)
235 /* Check that every given category is implemented by class. */
236 if (*categories->impl_strings) {
237 res = open_classes_key(key, impl_keyname, KEY_READ, &subkey);
238 if (res != ERROR_SUCCESS) return S_FALSE;
239 for (string = categories->impl_strings; *string; string += 39) {
241 res = open_classes_key(subkey, string, 0, &catkey);
242 if (res != ERROR_SUCCESS) {
251 /* Check that all categories required by class are given. */
252 res = open_classes_key(key, req_keyname, KEY_READ, &subkey);
253 if (res == ERROR_SUCCESS) {
254 for (index = 0; ; ++index) {
258 res = RegEnumKeyExW(subkey, index, keyname, &size,
259 NULL, NULL, NULL, NULL);
260 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
261 if (size != 38) continue; /* bogus catid in registry */
262 for (string = categories->req_strings; *string; string += 39)
263 if (!strcmpiW(string, keyname)) break;
275 /**********************************************************************
276 * COMCAT_ICatRegister_QueryInterface
278 static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
283 TRACE("%s\n",debugstr_guid(riid));
285 if (ppvObj == NULL) return E_POINTER;
287 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ICatRegister)) {
289 ICatRegister_AddRef(iface);
293 if (IsEqualGUID(riid, &IID_ICatInformation)) {
294 *ppvObj = &COMCAT_ComCatMgr.ICatInformation_iface;
295 ICatRegister_AddRef(iface);
299 return E_NOINTERFACE;
302 /**********************************************************************
303 * COMCAT_ICatRegister_AddRef
305 static ULONG WINAPI COMCAT_ICatRegister_AddRef(LPCATREGISTER iface)
307 return 2; /* non-heap based object */
310 /**********************************************************************
311 * COMCAT_ICatRegister_Release
313 static ULONG WINAPI COMCAT_ICatRegister_Release(LPCATREGISTER iface)
315 return 1; /* non-heap based object */
318 /**********************************************************************
319 * COMCAT_ICatRegister_RegisterCategories
321 static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
331 if (cCategories && rgci == NULL)
334 /* Create (or open) the component categories key. */
335 res = create_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
336 if (res != ERROR_SUCCESS) return E_FAIL;
338 for (; cCategories; --cCategories, ++rgci) {
339 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
344 /* Create (or open) the key for this category. */
345 if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
346 res = create_classes_key(comcat_key, keyname, KEY_READ|KEY_WRITE, &cat_key);
347 if (res != ERROR_SUCCESS) continue;
349 /* Set the value for this locale's description. */
350 wsprintfW(valname, fmt, rgci->lcid);
351 RegSetValueExW(cat_key, valname, 0, REG_SZ,
352 (CONST BYTE*)(rgci->szDescription),
353 (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR));
355 RegCloseKey(cat_key);
358 RegCloseKey(comcat_key);
362 /**********************************************************************
363 * COMCAT_ICatRegister_UnRegisterCategories
365 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
375 if (cCategories && rgcatid == NULL)
378 /* Open the component categories key. */
379 res = open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
380 if (res != ERROR_SUCCESS) return E_FAIL;
382 for (; cCategories; --cCategories, ++rgcatid) {
385 /* Delete the key for this category. */
386 if (!StringFromGUID2(rgcatid, keyname, 39)) continue;
387 RegDeleteKeyW(comcat_key, keyname);
390 RegCloseKey(comcat_key);
394 /**********************************************************************
395 * COMCAT_ICatRegister_RegisterClassImplCategories
397 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
405 return COMCAT_RegisterClassCategories(
406 rclsid, impl_keyname, cCategories, rgcatid);
409 /**********************************************************************
410 * COMCAT_ICatRegister_UnRegisterClassImplCategories
412 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
420 return COMCAT_UnRegisterClassCategories(
421 rclsid, impl_keyname, cCategories, rgcatid);
424 /**********************************************************************
425 * COMCAT_ICatRegister_RegisterClassReqCategories
427 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
435 return COMCAT_RegisterClassCategories(
436 rclsid, req_keyname, cCategories, rgcatid);
439 /**********************************************************************
440 * COMCAT_ICatRegister_UnRegisterClassReqCategories
442 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
450 return COMCAT_UnRegisterClassCategories(
451 rclsid, req_keyname, cCategories, rgcatid);
454 /**********************************************************************
455 * COMCAT_ICatInformation_QueryInterface
457 static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
458 LPCATINFORMATION iface,
462 return ICatRegister_QueryInterface(&COMCAT_ComCatMgr.ICatRegister_iface, riid, ppvObj);
465 /**********************************************************************
466 * COMCAT_ICatInformation_AddRef
468 static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
470 return ICatRegister_AddRef(&COMCAT_ComCatMgr.ICatRegister_iface);
473 /**********************************************************************
474 * COMCAT_ICatInformation_Release
476 static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
478 return ICatRegister_Release(&COMCAT_ComCatMgr.ICatRegister_iface);
481 /**********************************************************************
482 * COMCAT_ICatInformation_EnumCategories
484 static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
485 LPCATINFORMATION iface,
487 IEnumCATEGORYINFO **ppenumCatInfo)
491 if (ppenumCatInfo == NULL) return E_POINTER;
493 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
494 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
495 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
499 /**********************************************************************
500 * COMCAT_ICatInformation_GetCategoryDesc
502 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
503 LPCATINFORMATION iface,
508 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
509 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
510 'r', 'i', 'e', 's', '\\', 0 };
514 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid), lcid);
516 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
518 /* Open the key for this category. */
519 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
520 res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
521 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
523 /* Allocate a sensible amount of memory for the description. */
524 *ppszDesc = CoTaskMemAlloc(128 * sizeof(WCHAR));
525 if (*ppszDesc == NULL) {
527 return E_OUTOFMEMORY;
530 /* Get the description, and make sure it's null terminated. */
531 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
534 CoTaskMemFree(*ppszDesc);
541 /**********************************************************************
542 * COMCAT_ICatInformation_EnumClassesOfCategories
544 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
545 LPCATINFORMATION iface,
550 LPENUMCLSID *ppenumCLSID)
552 struct class_categories *categories;
556 if (cImplemented == (ULONG)-1)
558 if (cRequired == (ULONG)-1)
561 if (ppenumCLSID == NULL ||
562 (cImplemented && rgcatidImpl == NULL) ||
563 (cRequired && rgcatidReq == NULL)) return E_POINTER;
565 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
566 cRequired, rgcatidReq);
567 if (categories == NULL) return E_OUTOFMEMORY;
568 *ppenumCLSID = COMCAT_CLSID_IEnumGUID_Construct(categories);
569 if (*ppenumCLSID == NULL) {
570 HeapFree(GetProcessHeap(), 0, categories);
571 return E_OUTOFMEMORY;
573 IEnumGUID_AddRef(*ppenumCLSID);
577 /**********************************************************************
578 * COMCAT_ICatInformation_IsClassOfCategories
580 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
581 LPCATINFORMATION iface,
588 WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
590 struct class_categories *categories;
595 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented);
596 for (count = 0; count < cImplemented; ++count)
597 TRACE(" %s\n",debugstr_guid(&rgcatidImpl[count]));
598 TRACE("Required %u\n",cRequired);
599 for (count = 0; count < cRequired; ++count)
600 TRACE(" %s\n",debugstr_guid(&rgcatidReq[count]));
603 if ((cImplemented && rgcatidImpl == NULL) ||
604 (cRequired && rgcatidReq == NULL)) return E_POINTER;
606 res = StringFromGUID2(rclsid, keyname + 6, 39);
607 if (FAILED(res)) return res;
609 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
610 cRequired, rgcatidReq);
611 if (categories == NULL) return E_OUTOFMEMORY;
613 res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
614 if (res == ERROR_SUCCESS) {
615 res = COMCAT_IsClassOfCategories(key, categories);
617 } else res = S_FALSE;
619 HeapFree(GetProcessHeap(), 0, categories);
624 /**********************************************************************
625 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
627 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
628 LPCATINFORMATION iface,
630 LPENUMCATID *ppenumCATID)
632 static const WCHAR postfix[] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
633 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
634 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
636 TRACE("%s\n",debugstr_guid(rclsid));
638 if (rclsid == NULL || ppenumCATID == NULL)
641 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
642 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
646 /**********************************************************************
647 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
649 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
650 LPCATINFORMATION iface,
652 LPENUMCATID *ppenumCATID)
654 static const WCHAR postfix[] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
655 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
656 'r', 'i', 'e', 's', 0 };
658 TRACE("%s\n",debugstr_guid(rclsid));
660 if (rclsid == NULL || ppenumCATID == NULL)
663 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
664 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
668 /**********************************************************************
669 * COMCAT_ICatRegister_Vtbl
671 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
673 COMCAT_ICatRegister_QueryInterface,
674 COMCAT_ICatRegister_AddRef,
675 COMCAT_ICatRegister_Release,
676 COMCAT_ICatRegister_RegisterCategories,
677 COMCAT_ICatRegister_UnRegisterCategories,
678 COMCAT_ICatRegister_RegisterClassImplCategories,
679 COMCAT_ICatRegister_UnRegisterClassImplCategories,
680 COMCAT_ICatRegister_RegisterClassReqCategories,
681 COMCAT_ICatRegister_UnRegisterClassReqCategories
685 /**********************************************************************
686 * COMCAT_ICatInformation_Vtbl
688 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
690 COMCAT_ICatInformation_QueryInterface,
691 COMCAT_ICatInformation_AddRef,
692 COMCAT_ICatInformation_Release,
693 COMCAT_ICatInformation_EnumCategories,
694 COMCAT_ICatInformation_GetCategoryDesc,
695 COMCAT_ICatInformation_EnumClassesOfCategories,
696 COMCAT_ICatInformation_IsClassOfCategories,
697 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
698 COMCAT_ICatInformation_EnumReqCategoriesOfClass
701 /**********************************************************************
702 * COMCAT_IClassFactory_QueryInterface (also IUnknown)
704 static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
705 LPCLASSFACTORY iface,
709 TRACE("%s\n",debugstr_guid(riid));
711 if (ppvObj == NULL) return E_POINTER;
713 if (IsEqualGUID(riid, &IID_IUnknown) ||
714 IsEqualGUID(riid, &IID_IClassFactory))
717 IClassFactory_AddRef(iface);
721 return E_NOINTERFACE;
724 /**********************************************************************
725 * COMCAT_IClassFactory_AddRef (also IUnknown)
727 static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
729 return 2; /* non-heap based object */
732 /**********************************************************************
733 * COMCAT_IClassFactory_Release (also IUnknown)
735 static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface)
737 return 1; /* non-heap based object */
740 /**********************************************************************
741 * COMCAT_IClassFactory_CreateInstance
743 static HRESULT WINAPI COMCAT_IClassFactory_CreateInstance(
744 LPCLASSFACTORY iface,
750 TRACE("%s\n",debugstr_guid(riid));
752 if (ppvObj == NULL) return E_POINTER;
754 /* Don't support aggregation (Windows doesn't) */
755 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
757 res = ICatRegister_QueryInterface(&COMCAT_ComCatMgr.ICatRegister_iface, riid, ppvObj);
758 if (SUCCEEDED(res)) {
762 return CLASS_E_CLASSNOTAVAILABLE;
765 /**********************************************************************
766 * COMCAT_IClassFactory_LockServer
768 static HRESULT WINAPI COMCAT_IClassFactory_LockServer(
769 LPCLASSFACTORY iface,
772 FIXME("(%d), stub!\n",fLock);
776 /**********************************************************************
777 * static ClassFactory instance
779 static const IClassFactoryVtbl ComCatCFVtbl =
781 COMCAT_IClassFactory_QueryInterface,
782 COMCAT_IClassFactory_AddRef,
783 COMCAT_IClassFactory_Release,
784 COMCAT_IClassFactory_CreateInstance,
785 COMCAT_IClassFactory_LockServer
788 static const IClassFactoryVtbl *ComCatCF = &ComCatCFVtbl;
790 HRESULT ComCatCF_Create(REFIID riid, LPVOID *ppv)
792 return IClassFactory_QueryInterface((IClassFactory *)&ComCatCF, riid, ppv);
795 /**********************************************************************
796 * IEnumCATEGORYINFO implementation
798 * This implementation is not thread-safe. The manager itself is, but
799 * I can't imagine a valid use of an enumerator in several threads.
803 IEnumCATEGORYINFO IEnumCATEGORYINFO_iface;
808 } IEnumCATEGORYINFOImpl;
810 static inline IEnumCATEGORYINFOImpl *impl_from_IEnumCATEGORYINFO(IEnumCATEGORYINFO *iface)
812 return CONTAINING_RECORD(iface, IEnumCATEGORYINFOImpl, IEnumCATEGORYINFO_iface);
815 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(IEnumCATEGORYINFO *iface)
817 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
821 return InterlockedIncrement(&This->ref);
824 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
825 IEnumCATEGORYINFO *iface,
829 TRACE("%s\n",debugstr_guid(riid));
831 if (ppvObj == NULL) return E_POINTER;
833 if (IsEqualGUID(riid, &IID_IUnknown) ||
834 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
837 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
841 return E_NOINTERFACE;
844 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(IEnumCATEGORYINFO *iface)
846 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
851 ref = InterlockedDecrement(&This->ref);
853 if (This->key) RegCloseKey(This->key);
854 HeapFree(GetProcessHeap(), 0, This);
860 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
861 IEnumCATEGORYINFO *iface,
866 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
871 if (rgelt == NULL) return E_POINTER;
873 if (This->key) while (fetched < celt) {
880 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
881 NULL, NULL, NULL, NULL);
882 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
883 ++(This->next_index);
885 hr = CLSIDFromString(catid, &rgelt->catid);
886 if (FAILED(hr)) continue;
888 res = open_classes_key(This->key, catid, KEY_READ, &subkey);
889 if (res != ERROR_SUCCESS) continue;
891 hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
892 rgelt->szDescription, 128);
894 if (FAILED(hr)) continue;
896 rgelt->lcid = This->lcid;
901 if (pceltFetched) *pceltFetched = fetched;
902 return fetched == celt ? S_OK : S_FALSE;
905 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
906 IEnumCATEGORYINFO *iface,
909 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
913 This->next_index += celt;
914 /* This should return S_FALSE when there aren't celt elems to skip. */
918 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(IEnumCATEGORYINFO *iface)
920 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
924 This->next_index = 0;
928 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
929 IEnumCATEGORYINFO *iface,
930 IEnumCATEGORYINFO **ppenum)
932 IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
933 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
934 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
935 'r', 'i', 'e', 's', 0 };
936 IEnumCATEGORYINFOImpl *new_this;
940 if (ppenum == NULL) return E_POINTER;
942 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
943 if (new_this == NULL) return E_OUTOFMEMORY;
945 new_this->IEnumCATEGORYINFO_iface = This->IEnumCATEGORYINFO_iface;
947 new_this->lcid = This->lcid;
948 /* FIXME: could we more efficiently use DuplicateHandle? */
949 open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
950 new_this->next_index = This->next_index;
952 *ppenum = &new_this->IEnumCATEGORYINFO_iface;
956 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
958 COMCAT_IEnumCATEGORYINFO_QueryInterface,
959 COMCAT_IEnumCATEGORYINFO_AddRef,
960 COMCAT_IEnumCATEGORYINFO_Release,
961 COMCAT_IEnumCATEGORYINFO_Next,
962 COMCAT_IEnumCATEGORYINFO_Skip,
963 COMCAT_IEnumCATEGORYINFO_Reset,
964 COMCAT_IEnumCATEGORYINFO_Clone
967 static IEnumCATEGORYINFO *COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
969 IEnumCATEGORYINFOImpl *This;
971 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
973 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
974 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
975 'r', 'i', 'e', 's', 0 };
977 This->IEnumCATEGORYINFO_iface.lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
979 open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
981 return &This->IEnumCATEGORYINFO_iface;
984 /**********************************************************************
985 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
987 * This implementation is not thread-safe. The manager itself is, but
988 * I can't imagine a valid use of an enumerator in several threads.
992 const IEnumGUIDVtbl *lpVtbl;
994 struct class_categories *categories;
997 } CLSID_IEnumGUIDImpl;
999 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
1001 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1004 return InterlockedIncrement(&This->ref);
1007 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
1012 TRACE("%s\n",debugstr_guid(riid));
1014 if (ppvObj == NULL) return E_POINTER;
1016 if (IsEqualGUID(riid, &IID_IUnknown) ||
1017 IsEqualGUID(riid, &IID_IEnumGUID))
1020 COMCAT_CLSID_IEnumGUID_AddRef(iface);
1024 return E_NOINTERFACE;
1027 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
1029 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1034 ref = InterlockedDecrement(&This->ref);
1036 if (This->key) RegCloseKey(This->key);
1037 HeapFree(GetProcessHeap(), 0, This->categories);
1038 HeapFree(GetProcessHeap(), 0, This);
1044 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
1048 ULONG *pceltFetched)
1050 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1055 if (rgelt == NULL) return E_POINTER;
1057 if (This->key) while (fetched < celt) {
1064 res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
1065 NULL, NULL, NULL, NULL);
1066 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1067 ++(This->next_index);
1069 hr = CLSIDFromString(clsid, rgelt);
1070 if (FAILED(hr)) continue;
1072 res = open_classes_key(This->key, clsid, KEY_READ, &subkey);
1073 if (res != ERROR_SUCCESS) continue;
1075 hr = COMCAT_IsClassOfCategories(subkey, This->categories);
1076 RegCloseKey(subkey);
1077 if (hr != S_OK) continue;
1083 if (pceltFetched) *pceltFetched = fetched;
1084 return fetched == celt ? S_OK : S_FALSE;
1087 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Skip(
1091 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1095 This->next_index += celt;
1096 FIXME("Never returns S_FALSE\n");
1100 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface)
1102 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1106 This->next_index = 0;
1110 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
1114 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1115 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1116 CLSID_IEnumGUIDImpl *new_this;
1121 if (ppenum == NULL) return E_POINTER;
1123 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1124 if (new_this == NULL) return E_OUTOFMEMORY;
1126 new_this->lpVtbl = This->lpVtbl;
1128 size = HeapSize(GetProcessHeap(), 0, This->categories);
1129 new_this->categories =
1130 HeapAlloc(GetProcessHeap(), 0, size);
1131 if (new_this->categories == NULL) {
1132 HeapFree(GetProcessHeap(), 0, new_this);
1133 return E_OUTOFMEMORY;
1135 memcpy(new_this->categories, This->categories, size);
1136 /* FIXME: could we more efficiently use DuplicateHandle? */
1137 open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
1138 new_this->next_index = This->next_index;
1140 *ppenum = (LPENUMGUID)new_this;
1144 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl =
1146 COMCAT_CLSID_IEnumGUID_QueryInterface,
1147 COMCAT_CLSID_IEnumGUID_AddRef,
1148 COMCAT_CLSID_IEnumGUID_Release,
1149 COMCAT_CLSID_IEnumGUID_Next,
1150 COMCAT_CLSID_IEnumGUID_Skip,
1151 COMCAT_CLSID_IEnumGUID_Reset,
1152 COMCAT_CLSID_IEnumGUID_Clone
1155 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *categories)
1157 CLSID_IEnumGUIDImpl *This;
1159 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1161 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1163 This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
1164 This->categories = categories;
1165 open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
1167 return (LPENUMGUID)This;
1170 /**********************************************************************
1171 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1173 * This implementation is not thread-safe. The manager itself is, but
1174 * I can't imagine a valid use of an enumerator in several threads.
1178 const IEnumGUIDVtbl *lpVtbl;
1183 } CATID_IEnumGUIDImpl;
1185 static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
1187 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1190 return InterlockedIncrement(&This->ref);
1193 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
1198 TRACE("%s\n",debugstr_guid(riid));
1200 if (ppvObj == NULL) return E_POINTER;
1202 if (IsEqualGUID(riid, &IID_IUnknown) ||
1203 IsEqualGUID(riid, &IID_IEnumGUID))
1206 COMCAT_CATID_IEnumGUID_AddRef(iface);
1210 return E_NOINTERFACE;
1213 static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
1215 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1220 ref = InterlockedDecrement(&This->ref);
1222 if (This->key) RegCloseKey(This->key);
1223 HeapFree(GetProcessHeap(), 0, This);
1229 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
1233 ULONG *pceltFetched)
1235 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1240 if (rgelt == NULL) return E_POINTER;
1242 if (This->key) while (fetched < celt) {
1248 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1249 NULL, NULL, NULL, NULL);
1250 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1251 ++(This->next_index);
1253 hr = CLSIDFromString(catid, rgelt);
1254 if (FAILED(hr)) continue;
1260 if (pceltFetched) *pceltFetched = fetched;
1261 return fetched == celt ? S_OK : S_FALSE;
1264 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Skip(
1268 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1272 This->next_index += celt;
1273 FIXME("Never returns S_FALSE\n");
1277 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface)
1279 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1283 This->next_index = 0;
1287 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
1291 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1292 CATID_IEnumGUIDImpl *new_this;
1296 if (ppenum == NULL) return E_POINTER;
1298 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1299 if (new_this == NULL) return E_OUTOFMEMORY;
1301 new_this->lpVtbl = This->lpVtbl;
1303 lstrcpyW(new_this->keyname, This->keyname);
1304 /* FIXME: could we more efficiently use DuplicateHandle? */
1305 open_classes_key(HKEY_CLASSES_ROOT, new_this->keyname, KEY_READ, &new_this->key);
1306 new_this->next_index = This->next_index;
1308 *ppenum = (LPENUMGUID)new_this;
1312 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl =
1314 COMCAT_CATID_IEnumGUID_QueryInterface,
1315 COMCAT_CATID_IEnumGUID_AddRef,
1316 COMCAT_CATID_IEnumGUID_Release,
1317 COMCAT_CATID_IEnumGUID_Next,
1318 COMCAT_CATID_IEnumGUID_Skip,
1319 COMCAT_CATID_IEnumGUID_Reset,
1320 COMCAT_CATID_IEnumGUID_Clone
1323 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
1324 REFCLSID rclsid, LPCWSTR postfix)
1326 CATID_IEnumGUIDImpl *This;
1328 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1330 WCHAR prefix[] = { 'C', 'L', 'S', 'I', 'D', '\\' };
1332 This->lpVtbl = &COMCAT_CATID_IEnumGUID_Vtbl;
1333 memcpy(This->keyname, prefix, sizeof(prefix));
1334 StringFromGUID2(rclsid, This->keyname + 6, 39);
1335 lstrcpyW(This->keyname + 44, postfix);
1336 open_classes_key(HKEY_CLASSES_ROOT, This->keyname, KEY_READ, &This->key);
1338 return (LPENUMGUID)This;