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 if (*categories->impl_strings) {
236 res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
237 if (res != ERROR_SUCCESS) return S_FALSE;
238 for (string = categories->impl_strings; *string; string += 39) {
240 res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
241 if (res != ERROR_SUCCESS) {
250 /* Check that all categories required by class are given. */
251 res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
252 if (res == ERROR_SUCCESS) {
253 for (index = 0; ; ++index) {
257 res = RegEnumKeyExW(subkey, index, keyname, &size,
258 NULL, NULL, NULL, NULL);
259 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
260 if (size != 38) continue; /* bogus catid in registry */
261 for (string = categories->req_strings; *string; string += 39)
262 if (!strcmpiW(string, keyname)) break;
274 /**********************************************************************
275 * COMCAT_ICatRegister_QueryInterface
277 static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
282 ComCatMgrImpl *This = (ComCatMgrImpl *)iface;
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 IUnknown_AddRef(iface);
293 if (IsEqualGUID(riid, &IID_ICatInformation)) {
294 *ppvObj = &This->infVtbl;
295 IUnknown_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 = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
336 KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
337 if (res != ERROR_SUCCESS) return E_FAIL;
339 for (; cCategories; --cCategories, ++rgci) {
340 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
345 /* Create (or open) the key for this category. */
346 if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
347 res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
348 KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
349 if (res != ERROR_SUCCESS) continue;
351 /* Set the value for this locale's description. */
352 wsprintfW(valname, fmt, rgci->lcid);
353 RegSetValueExW(cat_key, valname, 0, REG_SZ,
354 (CONST BYTE*)(rgci->szDescription),
355 (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR));
357 RegCloseKey(cat_key);
360 RegCloseKey(comcat_key);
364 /**********************************************************************
365 * COMCAT_ICatRegister_UnRegisterCategories
367 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
377 if (cCategories && rgcatid == NULL)
380 /* Open the component categories key. */
381 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
382 KEY_READ | KEY_WRITE, &comcat_key);
383 if (res != ERROR_SUCCESS) return E_FAIL;
385 for (; cCategories; --cCategories, ++rgcatid) {
388 /* Delete the key for this category. */
389 if (!StringFromGUID2(rgcatid, keyname, 39)) continue;
390 RegDeleteKeyW(comcat_key, keyname);
393 RegCloseKey(comcat_key);
397 /**********************************************************************
398 * COMCAT_ICatRegister_RegisterClassImplCategories
400 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
408 return COMCAT_RegisterClassCategories(
409 rclsid, impl_keyname, cCategories, rgcatid);
412 /**********************************************************************
413 * COMCAT_ICatRegister_UnRegisterClassImplCategories
415 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
423 return COMCAT_UnRegisterClassCategories(
424 rclsid, impl_keyname, cCategories, rgcatid);
427 /**********************************************************************
428 * COMCAT_ICatRegister_RegisterClassReqCategories
430 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
438 return COMCAT_RegisterClassCategories(
439 rclsid, req_keyname, cCategories, rgcatid);
442 /**********************************************************************
443 * COMCAT_ICatRegister_UnRegisterClassReqCategories
445 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
453 return COMCAT_UnRegisterClassCategories(
454 rclsid, req_keyname, cCategories, rgcatid);
457 /**********************************************************************
458 * COMCAT_ICatInformation_QueryInterface
460 static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
461 LPCATINFORMATION iface,
465 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
466 return IUnknown_QueryInterface((LPUNKNOWN)This, riid, ppvObj);
469 /**********************************************************************
470 * COMCAT_ICatInformation_AddRef
472 static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
474 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
475 return IUnknown_AddRef((LPUNKNOWN)This);
478 /**********************************************************************
479 * COMCAT_ICatInformation_Release
481 static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
483 ComCatMgrImpl *This = impl_from_ICatInformation( iface );
484 return IUnknown_Release((LPUNKNOWN)This);
487 /**********************************************************************
488 * COMCAT_ICatInformation_EnumCategories
490 static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
491 LPCATINFORMATION iface,
493 LPENUMCATEGORYINFO *ppenumCatInfo)
497 if (ppenumCatInfo == NULL) return E_POINTER;
499 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
500 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
501 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
505 /**********************************************************************
506 * COMCAT_ICatInformation_GetCategoryDesc
508 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
509 LPCATINFORMATION iface,
514 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
515 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
516 'r', 'i', 'e', 's', '\\', 0 };
520 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid), lcid);
522 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
524 /* Open the key for this category. */
525 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
526 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
527 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
529 /* Allocate a sensible amount of memory for the description. */
530 *ppszDesc = CoTaskMemAlloc(128 * sizeof(WCHAR));
531 if (*ppszDesc == NULL) {
533 return E_OUTOFMEMORY;
536 /* Get the description, and make sure it's null terminated. */
537 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
540 CoTaskMemFree(*ppszDesc);
547 /**********************************************************************
548 * COMCAT_ICatInformation_EnumClassesOfCategories
550 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
551 LPCATINFORMATION iface,
556 LPENUMCLSID *ppenumCLSID)
558 struct class_categories *categories;
562 if (cImplemented == (ULONG)-1)
564 if (cRequired == (ULONG)-1)
567 if (ppenumCLSID == NULL ||
568 (cImplemented && rgcatidImpl == NULL) ||
569 (cRequired && rgcatidReq == NULL)) return E_POINTER;
571 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
572 cRequired, rgcatidReq);
573 if (categories == NULL) return E_OUTOFMEMORY;
574 *ppenumCLSID = COMCAT_CLSID_IEnumGUID_Construct(categories);
575 if (*ppenumCLSID == NULL) {
576 HeapFree(GetProcessHeap(), 0, categories);
577 return E_OUTOFMEMORY;
579 IEnumGUID_AddRef(*ppenumCLSID);
583 /**********************************************************************
584 * COMCAT_ICatInformation_IsClassOfCategories
586 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
587 LPCATINFORMATION iface,
594 WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
596 struct class_categories *categories;
599 if (WINE_TRACE_ON(ole)) {
601 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented);
602 for (count = 0; count < cImplemented; ++count)
603 TRACE(" %s\n",debugstr_guid(&rgcatidImpl[count]));
604 TRACE("Required %u\n",cRequired);
605 for (count = 0; count < cRequired; ++count)
606 TRACE(" %s\n",debugstr_guid(&rgcatidReq[count]));
609 if ((cImplemented && rgcatidImpl == NULL) ||
610 (cRequired && rgcatidReq == NULL)) return E_POINTER;
612 res = StringFromGUID2(rclsid, keyname + 6, 39);
613 if (FAILED(res)) return res;
615 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
616 cRequired, rgcatidReq);
617 if (categories == NULL) return E_OUTOFMEMORY;
619 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
620 if (res == ERROR_SUCCESS) {
621 res = COMCAT_IsClassOfCategories(key, categories);
623 } else res = S_FALSE;
625 HeapFree(GetProcessHeap(), 0, categories);
630 /**********************************************************************
631 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
633 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
634 LPCATINFORMATION iface,
636 LPENUMCATID *ppenumCATID)
638 static const WCHAR postfix[24] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
639 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
640 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
642 TRACE("%s\n",debugstr_guid(rclsid));
644 if (rclsid == NULL || ppenumCATID == NULL)
647 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
648 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
652 /**********************************************************************
653 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
655 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
656 LPCATINFORMATION iface,
658 LPENUMCATID *ppenumCATID)
660 static const WCHAR postfix[21] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
661 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
662 'r', 'i', 'e', 's', 0 };
664 TRACE("%s\n",debugstr_guid(rclsid));
666 if (rclsid == NULL || ppenumCATID == NULL)
669 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
670 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
674 /**********************************************************************
675 * COMCAT_ICatRegister_Vtbl
677 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
679 COMCAT_ICatRegister_QueryInterface,
680 COMCAT_ICatRegister_AddRef,
681 COMCAT_ICatRegister_Release,
682 COMCAT_ICatRegister_RegisterCategories,
683 COMCAT_ICatRegister_UnRegisterCategories,
684 COMCAT_ICatRegister_RegisterClassImplCategories,
685 COMCAT_ICatRegister_UnRegisterClassImplCategories,
686 COMCAT_ICatRegister_RegisterClassReqCategories,
687 COMCAT_ICatRegister_UnRegisterClassReqCategories
691 /**********************************************************************
692 * COMCAT_ICatInformation_Vtbl
694 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
696 COMCAT_ICatInformation_QueryInterface,
697 COMCAT_ICatInformation_AddRef,
698 COMCAT_ICatInformation_Release,
699 COMCAT_ICatInformation_EnumCategories,
700 COMCAT_ICatInformation_GetCategoryDesc,
701 COMCAT_ICatInformation_EnumClassesOfCategories,
702 COMCAT_ICatInformation_IsClassOfCategories,
703 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
704 COMCAT_ICatInformation_EnumReqCategoriesOfClass
707 /**********************************************************************
708 * static ComCatMgr instance
710 static ComCatMgrImpl COMCAT_ComCatMgr =
712 &COMCAT_ICatRegister_Vtbl,
713 &COMCAT_ICatInformation_Vtbl
716 /**********************************************************************
717 * COMCAT_IClassFactory_QueryInterface (also IUnknown)
719 static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
720 LPCLASSFACTORY iface,
724 TRACE("%s\n",debugstr_guid(riid));
726 if (ppvObj == NULL) return E_POINTER;
728 if (IsEqualGUID(riid, &IID_IUnknown) ||
729 IsEqualGUID(riid, &IID_IClassFactory))
732 IUnknown_AddRef(iface);
736 return E_NOINTERFACE;
739 /**********************************************************************
740 * COMCAT_IClassFactory_AddRef (also IUnknown)
742 static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
744 return 2; /* non-heap based object */
747 /**********************************************************************
748 * COMCAT_IClassFactory_Release (also IUnknown)
750 static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface)
752 return 1; /* non-heap based object */
755 /**********************************************************************
756 * COMCAT_IClassFactory_CreateInstance
758 static HRESULT WINAPI COMCAT_IClassFactory_CreateInstance(
759 LPCLASSFACTORY iface,
765 TRACE("%s\n",debugstr_guid(riid));
767 if (ppvObj == NULL) return E_POINTER;
769 /* Don't support aggregation (Windows doesn't) */
770 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
772 res = IUnknown_QueryInterface((LPUNKNOWN)&COMCAT_ComCatMgr, riid, ppvObj);
773 if (SUCCEEDED(res)) {
777 return CLASS_E_CLASSNOTAVAILABLE;
780 /**********************************************************************
781 * COMCAT_IClassFactory_LockServer
783 static HRESULT WINAPI COMCAT_IClassFactory_LockServer(
784 LPCLASSFACTORY iface,
787 FIXME("(%d), stub!\n",fLock);
791 /**********************************************************************
792 * static ClassFactory instance
794 static const IClassFactoryVtbl ComCatCFVtbl =
796 COMCAT_IClassFactory_QueryInterface,
797 COMCAT_IClassFactory_AddRef,
798 COMCAT_IClassFactory_Release,
799 COMCAT_IClassFactory_CreateInstance,
800 COMCAT_IClassFactory_LockServer
803 static const IClassFactoryVtbl *ComCatCF = &ComCatCFVtbl;
805 HRESULT ComCatCF_Create(REFIID riid, LPVOID *ppv)
807 return IClassFactory_QueryInterface((IClassFactory *)&ComCatCF, riid, ppv);
810 /**********************************************************************
811 * IEnumCATEGORYINFO implementation
813 * This implementation is not thread-safe. The manager itself is, but
814 * I can't imagine a valid use of an enumerator in several threads.
818 const IEnumCATEGORYINFOVtbl *lpVtbl;
823 } IEnumCATEGORYINFOImpl;
825 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
827 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
831 return InterlockedIncrement(&This->ref);
834 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
835 LPENUMCATEGORYINFO iface,
839 TRACE("%s\n",debugstr_guid(riid));
841 if (ppvObj == NULL) return E_POINTER;
843 if (IsEqualGUID(riid, &IID_IUnknown) ||
844 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
847 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
851 return E_NOINTERFACE;
854 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
856 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
861 ref = InterlockedDecrement(&This->ref);
863 if (This->key) RegCloseKey(This->key);
864 HeapFree(GetProcessHeap(), 0, This);
870 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
871 LPENUMCATEGORYINFO iface,
876 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
881 if (rgelt == NULL) return E_POINTER;
883 if (This->key) while (fetched < celt) {
890 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
891 NULL, NULL, NULL, NULL);
892 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
893 ++(This->next_index);
895 hr = CLSIDFromString(catid, &rgelt->catid);
896 if (FAILED(hr)) continue;
898 res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
899 if (res != ERROR_SUCCESS) continue;
901 hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
902 rgelt->szDescription, 128);
904 if (FAILED(hr)) continue;
906 rgelt->lcid = This->lcid;
911 if (pceltFetched) *pceltFetched = fetched;
912 return fetched == celt ? S_OK : S_FALSE;
915 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
916 LPENUMCATEGORYINFO iface,
919 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
923 This->next_index += celt;
924 /* This should return S_FALSE when there aren't celt elems to skip. */
928 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(LPENUMCATEGORYINFO iface)
930 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
934 This->next_index = 0;
938 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
939 LPENUMCATEGORYINFO iface,
940 IEnumCATEGORYINFO **ppenum)
942 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
943 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
944 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
945 'r', 'i', 'e', 's', 0 };
946 IEnumCATEGORYINFOImpl *new_this;
950 if (ppenum == NULL) return E_POINTER;
952 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
953 if (new_this == NULL) return E_OUTOFMEMORY;
955 new_this->lpVtbl = This->lpVtbl;
957 new_this->lcid = This->lcid;
958 /* FIXME: could we more efficiently use DuplicateHandle? */
959 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
960 new_this->next_index = This->next_index;
962 *ppenum = (LPENUMCATEGORYINFO)new_this;
966 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
968 COMCAT_IEnumCATEGORYINFO_QueryInterface,
969 COMCAT_IEnumCATEGORYINFO_AddRef,
970 COMCAT_IEnumCATEGORYINFO_Release,
971 COMCAT_IEnumCATEGORYINFO_Next,
972 COMCAT_IEnumCATEGORYINFO_Skip,
973 COMCAT_IEnumCATEGORYINFO_Reset,
974 COMCAT_IEnumCATEGORYINFO_Clone
977 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
979 IEnumCATEGORYINFOImpl *This;
981 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
983 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
984 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
985 'r', 'i', 'e', 's', 0 };
987 This->lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
989 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
991 return (LPENUMCATEGORYINFO)This;
994 /**********************************************************************
995 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
997 * This implementation is not thread-safe. The manager itself is, but
998 * I can't imagine a valid use of an enumerator in several threads.
1002 const IEnumGUIDVtbl *lpVtbl;
1004 struct class_categories *categories;
1007 } CLSID_IEnumGUIDImpl;
1009 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
1011 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1014 return InterlockedIncrement(&This->ref);
1017 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
1022 TRACE("%s\n",debugstr_guid(riid));
1024 if (ppvObj == NULL) return E_POINTER;
1026 if (IsEqualGUID(riid, &IID_IUnknown) ||
1027 IsEqualGUID(riid, &IID_IEnumGUID))
1030 COMCAT_CLSID_IEnumGUID_AddRef(iface);
1034 return E_NOINTERFACE;
1037 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
1039 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1044 ref = InterlockedDecrement(&This->ref);
1046 if (This->key) RegCloseKey(This->key);
1047 HeapFree(GetProcessHeap(), 0, This->categories);
1048 HeapFree(GetProcessHeap(), 0, This);
1054 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
1058 ULONG *pceltFetched)
1060 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1065 if (rgelt == NULL) return E_POINTER;
1067 if (This->key) while (fetched < celt) {
1074 res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
1075 NULL, NULL, NULL, NULL);
1076 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1077 ++(This->next_index);
1079 hr = CLSIDFromString(clsid, rgelt);
1080 if (FAILED(hr)) continue;
1082 res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
1083 if (res != ERROR_SUCCESS) continue;
1085 hr = COMCAT_IsClassOfCategories(subkey, This->categories);
1086 RegCloseKey(subkey);
1087 if (hr != S_OK) continue;
1093 if (pceltFetched) *pceltFetched = fetched;
1094 return fetched == celt ? S_OK : S_FALSE;
1097 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Skip(
1101 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1105 This->next_index += celt;
1106 FIXME("Never returns S_FALSE\n");
1110 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface)
1112 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1116 This->next_index = 0;
1120 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
1124 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1125 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1126 CLSID_IEnumGUIDImpl *new_this;
1131 if (ppenum == NULL) return E_POINTER;
1133 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1134 if (new_this == NULL) return E_OUTOFMEMORY;
1136 new_this->lpVtbl = This->lpVtbl;
1138 size = HeapSize(GetProcessHeap(), 0, This->categories);
1139 new_this->categories =
1140 HeapAlloc(GetProcessHeap(), 0, size);
1141 if (new_this->categories == NULL) {
1142 HeapFree(GetProcessHeap(), 0, new_this);
1143 return E_OUTOFMEMORY;
1145 memcpy(new_this->categories, This->categories, size);
1146 /* FIXME: could we more efficiently use DuplicateHandle? */
1147 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
1148 new_this->next_index = This->next_index;
1150 *ppenum = (LPENUMGUID)new_this;
1154 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl =
1156 COMCAT_CLSID_IEnumGUID_QueryInterface,
1157 COMCAT_CLSID_IEnumGUID_AddRef,
1158 COMCAT_CLSID_IEnumGUID_Release,
1159 COMCAT_CLSID_IEnumGUID_Next,
1160 COMCAT_CLSID_IEnumGUID_Skip,
1161 COMCAT_CLSID_IEnumGUID_Reset,
1162 COMCAT_CLSID_IEnumGUID_Clone
1165 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *categories)
1167 CLSID_IEnumGUIDImpl *This;
1169 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1171 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1173 This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
1174 This->categories = categories;
1175 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
1177 return (LPENUMGUID)This;
1180 /**********************************************************************
1181 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1183 * This implementation is not thread-safe. The manager itself is, but
1184 * I can't imagine a valid use of an enumerator in several threads.
1188 const IEnumGUIDVtbl *lpVtbl;
1193 } CATID_IEnumGUIDImpl;
1195 static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
1197 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1200 return InterlockedIncrement(&This->ref);
1203 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
1208 TRACE("%s\n",debugstr_guid(riid));
1210 if (ppvObj == NULL) return E_POINTER;
1212 if (IsEqualGUID(riid, &IID_IUnknown) ||
1213 IsEqualGUID(riid, &IID_IEnumGUID))
1216 COMCAT_CATID_IEnumGUID_AddRef(iface);
1220 return E_NOINTERFACE;
1223 static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
1225 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1230 ref = InterlockedDecrement(&This->ref);
1232 if (This->key) RegCloseKey(This->key);
1233 HeapFree(GetProcessHeap(), 0, This);
1239 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
1243 ULONG *pceltFetched)
1245 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1250 if (rgelt == NULL) return E_POINTER;
1252 if (This->key) while (fetched < celt) {
1258 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1259 NULL, NULL, NULL, NULL);
1260 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1261 ++(This->next_index);
1263 hr = CLSIDFromString(catid, rgelt);
1264 if (FAILED(hr)) continue;
1270 if (pceltFetched) *pceltFetched = fetched;
1271 return fetched == celt ? S_OK : S_FALSE;
1274 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Skip(
1278 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1282 This->next_index += celt;
1283 FIXME("Never returns S_FALSE\n");
1287 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface)
1289 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1293 This->next_index = 0;
1297 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
1301 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1302 CATID_IEnumGUIDImpl *new_this;
1306 if (ppenum == NULL) return E_POINTER;
1308 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1309 if (new_this == NULL) return E_OUTOFMEMORY;
1311 new_this->lpVtbl = This->lpVtbl;
1313 lstrcpyW(new_this->keyname, This->keyname);
1314 /* FIXME: could we more efficiently use DuplicateHandle? */
1315 RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
1316 new_this->next_index = This->next_index;
1318 *ppenum = (LPENUMGUID)new_this;
1322 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl =
1324 COMCAT_CATID_IEnumGUID_QueryInterface,
1325 COMCAT_CATID_IEnumGUID_AddRef,
1326 COMCAT_CATID_IEnumGUID_Release,
1327 COMCAT_CATID_IEnumGUID_Next,
1328 COMCAT_CATID_IEnumGUID_Skip,
1329 COMCAT_CATID_IEnumGUID_Reset,
1330 COMCAT_CATID_IEnumGUID_Clone
1333 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
1334 REFCLSID rclsid, LPCWSTR postfix)
1336 CATID_IEnumGUIDImpl *This;
1338 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1340 WCHAR prefix[6] = { 'C', 'L', 'S', 'I', 'D', '\\' };
1342 This->lpVtbl = &COMCAT_CATID_IEnumGUID_Vtbl;
1343 memcpy(This->keyname, prefix, sizeof(prefix));
1344 StringFromGUID2(rclsid, This->keyname + 6, 39);
1345 lstrcpyW(This->keyname + 44, postfix);
1346 RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
1348 return (LPENUMGUID)This;