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 "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41 const ICatRegisterVtbl *lpVtbl;
42 const ICatInformationVtbl *infVtbl;
45 struct class_categories {
50 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid);
51 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *class_categories);
52 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(REFCLSID rclsid, LPCWSTR impl_req);
54 /**********************************************************************
55 * File-scope string constants
57 static const WCHAR comcat_keyname[] = {
58 'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0 };
59 static const WCHAR impl_keyname[] = {
60 'I','m','p','l','e','m','e','n','t','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
61 static const WCHAR req_keyname[] = {
62 'R','e','q','u','i','r','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
63 static const WCHAR clsid_keyname[] = { 'C','L','S','I','D',0 };
66 static inline ComCatMgrImpl *impl_from_ICatInformation( ICatInformation *iface )
68 return (ComCatMgrImpl *)((char*)iface - FIELD_OFFSET(ComCatMgrImpl, infVtbl));
72 /**********************************************************************
73 * COMCAT_RegisterClassCategories
75 static HRESULT COMCAT_RegisterClassCategories(
83 HKEY clsid_key, class_key, type_key;
85 if (cCategories && rgcatid == NULL) return E_POINTER;
87 /* Format the class key name. */
88 res = StringFromGUID2(rclsid, keyname, 39);
89 if (FAILED(res)) return res;
91 /* Create (or open) the CLSID key. */
92 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
93 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
94 if (res != ERROR_SUCCESS) return E_FAIL;
96 /* Create (or open) the class key. */
97 res = RegCreateKeyExW(clsid_key, keyname, 0, NULL, 0,
98 KEY_READ | KEY_WRITE, NULL, &class_key, NULL);
99 if (res == ERROR_SUCCESS) {
100 /* Create (or open) the category type key. */
101 res = RegCreateKeyExW(class_key, type, 0, NULL, 0,
102 KEY_READ | KEY_WRITE, NULL, &type_key, NULL);
103 if (res == ERROR_SUCCESS) {
104 for (; cCategories; --cCategories, ++rgcatid) {
107 /* Format the category key name. */
108 res = StringFromGUID2(rgcatid, keyname, 39);
109 if (FAILED(res)) continue;
111 /* Do the register. */
112 res = RegCreateKeyExW(type_key, keyname, 0, NULL, 0,
113 KEY_READ | KEY_WRITE, NULL, &key, NULL);
114 if (res == ERROR_SUCCESS) RegCloseKey(key);
118 RegCloseKey(class_key);
120 RegCloseKey(clsid_key);
125 /**********************************************************************
126 * COMCAT_UnRegisterClassCategories
128 static HRESULT COMCAT_UnRegisterClassCategories(
132 const CATID *rgcatid)
134 WCHAR keyname[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
138 if (cCategories && rgcatid == NULL) return E_POINTER;
140 /* Format the class category type key name. */
141 res = StringFromGUID2(rclsid, keyname + 6, 39);
142 if (FAILED(res)) return res;
144 lstrcpyW(keyname + 45, type);
146 /* Open the class category type key. */
147 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0,
148 KEY_READ | KEY_WRITE, &type_key);
149 if (res != ERROR_SUCCESS) return E_FAIL;
151 for (; cCategories; --cCategories, ++rgcatid) {
152 /* Format the category key name. */
153 res = StringFromGUID2(rgcatid, keyname, 39);
154 if (FAILED(res)) continue;
156 /* Do the unregister. */
157 RegDeleteKeyW(type_key, keyname);
159 RegCloseKey(type_key);
164 /**********************************************************************
165 * COMCAT_GetCategoryDesc
167 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
170 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
173 DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);
175 if (pszDesc == NULL) return E_INVALIDARG;
177 /* FIXME: lcid comparisons are more complex than this! */
178 wsprintfW(valname, fmt, lcid);
179 res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
180 if (res != ERROR_SUCCESS || type != REG_SZ) {
181 FIXME("Simplified lcid comparison\n");
182 return CAT_E_NODESCRIPTION;
184 pszDesc[size / sizeof(WCHAR)] = 0;
189 /**********************************************************************
190 * COMCAT_PrepareClassCategories
192 static struct class_categories *COMCAT_PrepareClassCategories(
193 ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids)
195 struct class_categories *categories;
198 categories = HeapAlloc(
199 GetProcessHeap(), HEAP_ZERO_MEMORY,
200 sizeof(struct class_categories) +
201 ((impl_count + req_count) * 39 + 2) * sizeof(WCHAR));
202 if (categories == NULL) return categories;
204 strings = (WCHAR *)(categories + 1);
205 categories->impl_strings = strings;
206 while (impl_count--) {
207 StringFromGUID2(impl_catids++, strings, 39);
212 categories->req_strings = strings;
213 while (req_count--) {
214 StringFromGUID2(req_catids++, strings, 39);
222 /**********************************************************************
223 * COMCAT_IsClassOfCategories
225 static HRESULT COMCAT_IsClassOfCategories(
227 struct class_categories const* categories)
234 /* Check that every given category is implemented by class. */
235 res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
236 if (res != ERROR_SUCCESS) return S_FALSE;
237 for (string = categories->impl_strings; *string; string += 39) {
239 res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
240 if (res != ERROR_SUCCESS) {
248 /* Check that all categories required by class are given. */
249 res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
250 if (res == ERROR_SUCCESS) {
251 for (index = 0; ; ++index) {
255 res = RegEnumKeyExW(subkey, index, keyname, &size,
256 NULL, NULL, NULL, NULL);
257 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
258 if (size != 38) continue; /* bogus catid in registry */
259 for (string = categories->req_strings; *string; string += 39)
260 if (!strcmpiW(string, keyname)) break;
272 /**********************************************************************
273 * COMCAT_ICatRegister_QueryInterface
275 static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
280 ComCatMgrImpl *This = (ComCatMgrImpl *)iface;
281 TRACE("%s\n",debugstr_guid(riid));
283 if (ppvObj == NULL) return E_POINTER;
285 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ICatRegister)) {
287 IUnknown_AddRef(iface);
291 if (IsEqualGUID(riid, &IID_ICatInformation)) {
292 *ppvObj = &This->infVtbl;
293 IUnknown_AddRef(iface);
297 return E_NOINTERFACE;
300 /**********************************************************************
301 * COMCAT_ICatRegister_AddRef
303 static ULONG WINAPI COMCAT_ICatRegister_AddRef(LPCATREGISTER iface)
305 return 2; /* non-heap based object */
308 /**********************************************************************
309 * COMCAT_ICatRegister_Release
311 static ULONG WINAPI COMCAT_ICatRegister_Release(LPCATREGISTER iface)
313 return 1; /* non-heap based object */
316 /**********************************************************************
317 * COMCAT_ICatRegister_RegisterCategories
319 static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
329 if (cCategories && rgci == NULL)
332 /* Create (or open) the component categories key. */
333 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
334 KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
335 if (res != ERROR_SUCCESS) return E_FAIL;
337 for (; cCategories; --cCategories, ++rgci) {
338 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
343 /* Create (or open) the key for this category. */
344 if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
345 res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
346 KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
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 = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
380 KEY_READ | KEY_WRITE, &comcat_key);
381 if (res != ERROR_SUCCESS) return E_FAIL;
383 for (; cCategories; --cCategories, ++rgcatid) {
386 /* Delete the key for this category. */
387 if (!StringFromGUID2(rgcatid, keyname, 39)) continue;
388 RegDeleteKeyW(comcat_key, keyname);
391 RegCloseKey(comcat_key);
395 /**********************************************************************
396 * COMCAT_ICatRegister_RegisterClassImplCategories
398 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
406 return COMCAT_RegisterClassCategories(
407 rclsid, impl_keyname, cCategories, rgcatid);
410 /**********************************************************************
411 * COMCAT_ICatRegister_UnRegisterClassImplCategories
413 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
421 return COMCAT_UnRegisterClassCategories(
422 rclsid, impl_keyname, cCategories, rgcatid);
425 /**********************************************************************
426 * COMCAT_ICatRegister_RegisterClassReqCategories
428 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
436 return COMCAT_RegisterClassCategories(
437 rclsid, req_keyname, cCategories, rgcatid);
440 /**********************************************************************
441 * COMCAT_ICatRegister_UnRegisterClassReqCategories
443 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
451 return COMCAT_UnRegisterClassCategories(
452 rclsid, req_keyname, cCategories, rgcatid);
455 /**********************************************************************
456 * COMCAT_ICatInformation_QueryInterface
458 static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
459 LPCATINFORMATION iface,
463 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
464 return IUnknown_QueryInterface((LPUNKNOWN)This, riid, ppvObj);
467 /**********************************************************************
468 * COMCAT_ICatInformation_AddRef
470 static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
472 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
473 return IUnknown_AddRef((LPUNKNOWN)This);
476 /**********************************************************************
477 * COMCAT_ICatInformation_Release
479 static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
481 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
482 return IUnknown_Release((LPUNKNOWN)This);
485 /**********************************************************************
486 * COMCAT_ICatInformation_EnumCategories
488 static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
489 LPCATINFORMATION iface,
491 LPENUMCATEGORYINFO *ppenumCatInfo)
495 if (ppenumCatInfo == NULL) return E_POINTER;
497 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
498 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
499 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
503 /**********************************************************************
504 * COMCAT_ICatInformation_GetCategoryDesc
506 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
507 LPCATINFORMATION iface,
512 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
513 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
514 'r', 'i', 'e', 's', '\\', 0 };
518 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid), lcid);
520 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
522 /* Open the key for this category. */
523 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
524 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
525 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
527 /* Allocate a sensible amount of memory for the description. */
528 *ppszDesc = CoTaskMemAlloc(128 * sizeof(WCHAR));
529 if (*ppszDesc == NULL) {
531 return E_OUTOFMEMORY;
534 /* Get the description, and make sure it's null terminated. */
535 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
538 CoTaskMemFree(*ppszDesc);
545 /**********************************************************************
546 * COMCAT_ICatInformation_EnumClassesOfCategories
548 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
549 LPCATINFORMATION iface,
554 LPENUMCLSID *ppenumCLSID)
556 struct class_categories *categories;
560 if (cImplemented == (ULONG)-1)
562 if (cRequired == (ULONG)-1)
565 if (ppenumCLSID == NULL ||
566 (cImplemented && rgcatidImpl == NULL) ||
567 (cRequired && rgcatidReq == NULL)) return E_POINTER;
569 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
570 cRequired, rgcatidReq);
571 if (categories == NULL) return E_OUTOFMEMORY;
572 *ppenumCLSID = COMCAT_CLSID_IEnumGUID_Construct(categories);
573 if (*ppenumCLSID == NULL) {
574 HeapFree(GetProcessHeap(), 0, categories);
575 return E_OUTOFMEMORY;
577 IEnumGUID_AddRef(*ppenumCLSID);
581 /**********************************************************************
582 * COMCAT_ICatInformation_IsClassOfCategories
584 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
585 LPCATINFORMATION iface,
592 WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
594 struct class_categories *categories;
597 if (WINE_TRACE_ON(ole)) {
599 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented);
600 for (count = 0; count < cImplemented; ++count)
601 TRACE(" %s\n",debugstr_guid(&rgcatidImpl[count]));
602 TRACE("Required %u\n",cRequired);
603 for (count = 0; count < cRequired; ++count)
604 TRACE(" %s\n",debugstr_guid(&rgcatidReq[count]));
607 if ((cImplemented && rgcatidImpl == NULL) ||
608 (cRequired && rgcatidReq == NULL)) return E_POINTER;
610 res = StringFromGUID2(rclsid, keyname + 6, 39);
611 if (FAILED(res)) return res;
613 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
614 cRequired, rgcatidReq);
615 if (categories == NULL) return E_OUTOFMEMORY;
617 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
618 if (res == ERROR_SUCCESS) {
619 res = COMCAT_IsClassOfCategories(key, categories);
621 } else res = S_FALSE;
623 HeapFree(GetProcessHeap(), 0, categories);
628 /**********************************************************************
629 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
631 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
632 LPCATINFORMATION iface,
634 LPENUMCATID *ppenumCATID)
636 static const WCHAR postfix[24] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
637 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
638 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
640 TRACE("%s\n",debugstr_guid(rclsid));
642 if (rclsid == NULL || ppenumCATID == NULL)
645 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
646 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
650 /**********************************************************************
651 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
653 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
654 LPCATINFORMATION iface,
656 LPENUMCATID *ppenumCATID)
658 static const WCHAR postfix[21] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
659 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
660 'r', 'i', 'e', 's', 0 };
662 TRACE("%s\n",debugstr_guid(rclsid));
664 if (rclsid == NULL || ppenumCATID == NULL)
667 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
668 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
672 /**********************************************************************
673 * COMCAT_ICatRegister_Vtbl
675 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
677 COMCAT_ICatRegister_QueryInterface,
678 COMCAT_ICatRegister_AddRef,
679 COMCAT_ICatRegister_Release,
680 COMCAT_ICatRegister_RegisterCategories,
681 COMCAT_ICatRegister_UnRegisterCategories,
682 COMCAT_ICatRegister_RegisterClassImplCategories,
683 COMCAT_ICatRegister_UnRegisterClassImplCategories,
684 COMCAT_ICatRegister_RegisterClassReqCategories,
685 COMCAT_ICatRegister_UnRegisterClassReqCategories
689 /**********************************************************************
690 * COMCAT_ICatInformation_Vtbl
692 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
694 COMCAT_ICatInformation_QueryInterface,
695 COMCAT_ICatInformation_AddRef,
696 COMCAT_ICatInformation_Release,
697 COMCAT_ICatInformation_EnumCategories,
698 COMCAT_ICatInformation_GetCategoryDesc,
699 COMCAT_ICatInformation_EnumClassesOfCategories,
700 COMCAT_ICatInformation_IsClassOfCategories,
701 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
702 COMCAT_ICatInformation_EnumReqCategoriesOfClass
705 /**********************************************************************
706 * static ComCatMgr instance
708 static ComCatMgrImpl COMCAT_ComCatMgr =
710 &COMCAT_ICatRegister_Vtbl,
711 &COMCAT_ICatInformation_Vtbl
714 /**********************************************************************
715 * COMCAT_IClassFactory_QueryInterface (also IUnknown)
717 static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
718 LPCLASSFACTORY iface,
722 TRACE("%s\n",debugstr_guid(riid));
724 if (ppvObj == NULL) return E_POINTER;
726 if (IsEqualGUID(riid, &IID_IUnknown) ||
727 IsEqualGUID(riid, &IID_IClassFactory))
730 IUnknown_AddRef(iface);
734 return E_NOINTERFACE;
737 /**********************************************************************
738 * COMCAT_IClassFactory_AddRef (also IUnknown)
740 static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
742 return 2; /* non-heap based object */
745 /**********************************************************************
746 * COMCAT_IClassFactory_Release (also IUnknown)
748 static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface)
750 return 1; /* non-heap based object */
753 /**********************************************************************
754 * COMCAT_IClassFactory_CreateInstance
756 static HRESULT WINAPI COMCAT_IClassFactory_CreateInstance(
757 LPCLASSFACTORY iface,
763 TRACE("%s\n",debugstr_guid(riid));
765 if (ppvObj == NULL) return E_POINTER;
767 /* Don't support aggregation (Windows doesn't) */
768 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
770 res = IUnknown_QueryInterface((LPUNKNOWN)&COMCAT_ComCatMgr, riid, ppvObj);
771 if (SUCCEEDED(res)) {
775 return CLASS_E_CLASSNOTAVAILABLE;
778 /**********************************************************************
779 * COMCAT_IClassFactory_LockServer
781 static HRESULT WINAPI COMCAT_IClassFactory_LockServer(
782 LPCLASSFACTORY iface,
785 FIXME("(%d), stub!\n",fLock);
789 /**********************************************************************
790 * static ClassFactory instance
792 static const IClassFactoryVtbl ComCatCFVtbl =
794 COMCAT_IClassFactory_QueryInterface,
795 COMCAT_IClassFactory_AddRef,
796 COMCAT_IClassFactory_Release,
797 COMCAT_IClassFactory_CreateInstance,
798 COMCAT_IClassFactory_LockServer
801 static const IClassFactoryVtbl *ComCatCF = &ComCatCFVtbl;
803 HRESULT ComCatCF_Create(REFIID riid, LPVOID *ppv)
805 return IClassFactory_QueryInterface((IClassFactory *)&ComCatCF, riid, ppv);
808 /**********************************************************************
809 * IEnumCATEGORYINFO implementation
811 * This implementation is not thread-safe. The manager itself is, but
812 * I can't imagine a valid use of an enumerator in several threads.
816 const IEnumCATEGORYINFOVtbl *lpVtbl;
821 } IEnumCATEGORYINFOImpl;
823 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
825 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
829 return InterlockedIncrement(&This->ref);
832 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
833 LPENUMCATEGORYINFO iface,
837 TRACE("%s\n",debugstr_guid(riid));
839 if (ppvObj == NULL) return E_POINTER;
841 if (IsEqualGUID(riid, &IID_IUnknown) ||
842 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
845 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
849 return E_NOINTERFACE;
852 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
854 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
859 ref = InterlockedDecrement(&This->ref);
861 if (This->key) RegCloseKey(This->key);
862 HeapFree(GetProcessHeap(), 0, This);
868 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
869 LPENUMCATEGORYINFO iface,
874 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
879 if (rgelt == NULL) return E_POINTER;
881 if (This->key) while (fetched < celt) {
888 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
889 NULL, NULL, NULL, NULL);
890 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
891 ++(This->next_index);
893 hr = CLSIDFromString(catid, &rgelt->catid);
894 if (FAILED(hr)) continue;
896 res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
897 if (res != ERROR_SUCCESS) continue;
899 hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
900 rgelt->szDescription, 128);
902 if (FAILED(hr)) continue;
904 rgelt->lcid = This->lcid;
909 if (pceltFetched) *pceltFetched = fetched;
910 return fetched == celt ? S_OK : S_FALSE;
913 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
914 LPENUMCATEGORYINFO iface,
917 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
921 This->next_index += celt;
922 /* This should return S_FALSE when there aren't celt elems to skip. */
926 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(LPENUMCATEGORYINFO iface)
928 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
932 This->next_index = 0;
936 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
937 LPENUMCATEGORYINFO iface,
938 IEnumCATEGORYINFO **ppenum)
940 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
941 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
942 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
943 'r', 'i', 'e', 's', 0 };
944 IEnumCATEGORYINFOImpl *new_this;
948 if (ppenum == NULL) return E_POINTER;
950 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
951 if (new_this == NULL) return E_OUTOFMEMORY;
953 new_this->lpVtbl = This->lpVtbl;
955 new_this->lcid = This->lcid;
956 /* FIXME: could we more efficiently use DuplicateHandle? */
957 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
958 new_this->next_index = This->next_index;
960 *ppenum = (LPENUMCATEGORYINFO)new_this;
964 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
966 COMCAT_IEnumCATEGORYINFO_QueryInterface,
967 COMCAT_IEnumCATEGORYINFO_AddRef,
968 COMCAT_IEnumCATEGORYINFO_Release,
969 COMCAT_IEnumCATEGORYINFO_Next,
970 COMCAT_IEnumCATEGORYINFO_Skip,
971 COMCAT_IEnumCATEGORYINFO_Reset,
972 COMCAT_IEnumCATEGORYINFO_Clone
975 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
977 IEnumCATEGORYINFOImpl *This;
979 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
981 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
982 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
983 'r', 'i', 'e', 's', 0 };
985 This->lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
987 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
989 return (LPENUMCATEGORYINFO)This;
992 /**********************************************************************
993 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
995 * This implementation is not thread-safe. The manager itself is, but
996 * I can't imagine a valid use of an enumerator in several threads.
1000 const IEnumGUIDVtbl *lpVtbl;
1002 struct class_categories *categories;
1005 } CLSID_IEnumGUIDImpl;
1007 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
1009 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1012 return InterlockedIncrement(&This->ref);
1015 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
1020 TRACE("%s\n",debugstr_guid(riid));
1022 if (ppvObj == NULL) return E_POINTER;
1024 if (IsEqualGUID(riid, &IID_IUnknown) ||
1025 IsEqualGUID(riid, &IID_IEnumGUID))
1028 COMCAT_CLSID_IEnumGUID_AddRef(iface);
1032 return E_NOINTERFACE;
1035 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
1037 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1042 ref = InterlockedDecrement(&This->ref);
1044 if (This->key) RegCloseKey(This->key);
1045 HeapFree(GetProcessHeap(), 0, This->categories);
1046 HeapFree(GetProcessHeap(), 0, This);
1052 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
1056 ULONG *pceltFetched)
1058 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1063 if (rgelt == NULL) return E_POINTER;
1065 if (This->key) while (fetched < celt) {
1072 res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
1073 NULL, NULL, NULL, NULL);
1074 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1075 ++(This->next_index);
1077 hr = CLSIDFromString(clsid, rgelt);
1078 if (FAILED(hr)) continue;
1080 res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
1081 if (res != ERROR_SUCCESS) continue;
1083 hr = COMCAT_IsClassOfCategories(subkey, This->categories);
1084 RegCloseKey(subkey);
1085 if (hr != S_OK) continue;
1091 if (pceltFetched) *pceltFetched = fetched;
1092 return fetched == celt ? S_OK : S_FALSE;
1095 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Skip(
1099 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1103 This->next_index += celt;
1104 FIXME("Never returns S_FALSE\n");
1108 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface)
1110 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1114 This->next_index = 0;
1118 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
1122 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1123 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1124 CLSID_IEnumGUIDImpl *new_this;
1129 if (ppenum == NULL) return E_POINTER;
1131 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1132 if (new_this == NULL) return E_OUTOFMEMORY;
1134 new_this->lpVtbl = This->lpVtbl;
1136 size = HeapSize(GetProcessHeap(), 0, This->categories);
1137 new_this->categories =
1138 HeapAlloc(GetProcessHeap(), 0, size);
1139 if (new_this->categories == NULL) {
1140 HeapFree(GetProcessHeap(), 0, new_this);
1141 return E_OUTOFMEMORY;
1143 memcpy(new_this->categories, This->categories, size);
1144 /* FIXME: could we more efficiently use DuplicateHandle? */
1145 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
1146 new_this->next_index = This->next_index;
1148 *ppenum = (LPENUMGUID)new_this;
1152 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl =
1154 COMCAT_CLSID_IEnumGUID_QueryInterface,
1155 COMCAT_CLSID_IEnumGUID_AddRef,
1156 COMCAT_CLSID_IEnumGUID_Release,
1157 COMCAT_CLSID_IEnumGUID_Next,
1158 COMCAT_CLSID_IEnumGUID_Skip,
1159 COMCAT_CLSID_IEnumGUID_Reset,
1160 COMCAT_CLSID_IEnumGUID_Clone
1163 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *categories)
1165 CLSID_IEnumGUIDImpl *This;
1167 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1169 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1171 This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
1172 This->categories = categories;
1173 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
1175 return (LPENUMGUID)This;
1178 /**********************************************************************
1179 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1181 * This implementation is not thread-safe. The manager itself is, but
1182 * I can't imagine a valid use of an enumerator in several threads.
1186 const IEnumGUIDVtbl *lpVtbl;
1191 } CATID_IEnumGUIDImpl;
1193 static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
1195 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1198 return InterlockedIncrement(&This->ref);
1201 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
1206 TRACE("%s\n",debugstr_guid(riid));
1208 if (ppvObj == NULL) return E_POINTER;
1210 if (IsEqualGUID(riid, &IID_IUnknown) ||
1211 IsEqualGUID(riid, &IID_IEnumGUID))
1214 COMCAT_CATID_IEnumGUID_AddRef(iface);
1218 return E_NOINTERFACE;
1221 static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
1223 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1228 ref = InterlockedDecrement(&This->ref);
1230 if (This->key) RegCloseKey(This->key);
1231 HeapFree(GetProcessHeap(), 0, This);
1237 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
1241 ULONG *pceltFetched)
1243 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1248 if (rgelt == NULL) return E_POINTER;
1250 if (This->key) while (fetched < celt) {
1256 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1257 NULL, NULL, NULL, NULL);
1258 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1259 ++(This->next_index);
1261 hr = CLSIDFromString(catid, rgelt);
1262 if (FAILED(hr)) continue;
1268 if (pceltFetched) *pceltFetched = fetched;
1269 return fetched == celt ? S_OK : S_FALSE;
1272 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Skip(
1276 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1280 This->next_index += celt;
1281 FIXME("Never returns S_FALSE\n");
1285 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface)
1287 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1291 This->next_index = 0;
1295 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
1299 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1300 CATID_IEnumGUIDImpl *new_this;
1304 if (ppenum == NULL) return E_POINTER;
1306 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1307 if (new_this == NULL) return E_OUTOFMEMORY;
1309 new_this->lpVtbl = This->lpVtbl;
1311 lstrcpyW(new_this->keyname, This->keyname);
1312 /* FIXME: could we more efficiently use DuplicateHandle? */
1313 RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
1314 new_this->next_index = This->next_index;
1316 *ppenum = (LPENUMGUID)new_this;
1320 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl =
1322 COMCAT_CATID_IEnumGUID_QueryInterface,
1323 COMCAT_CATID_IEnumGUID_AddRef,
1324 COMCAT_CATID_IEnumGUID_Release,
1325 COMCAT_CATID_IEnumGUID_Next,
1326 COMCAT_CATID_IEnumGUID_Skip,
1327 COMCAT_CATID_IEnumGUID_Reset,
1328 COMCAT_CATID_IEnumGUID_Clone
1331 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
1332 REFCLSID rclsid, LPCWSTR postfix)
1334 CATID_IEnumGUIDImpl *This;
1336 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1338 WCHAR prefix[6] = { 'C', 'L', 'S', 'I', 'D', '\\' };
1340 This->lpVtbl = &COMCAT_CATID_IEnumGUID_Vtbl;
1341 memcpy(This->keyname, prefix, sizeof(prefix));
1342 StringFromGUID2(rclsid, This->keyname + 6, 39);
1343 lstrcpyW(This->keyname + 44, postfix);
1344 RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
1346 return (LPENUMGUID)This;