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
59 ULONG size
; /* total length, including structure itself */
64 static HRESULT
EnumCATEGORYINFO_Construct(LCID lcid
, IEnumCATEGORYINFO
**ret
);
65 static HRESULT
CLSIDEnumGUID_Construct(struct class_categories
*class_categories
, IEnumCLSID
**ret
);
66 static HRESULT
CATIDEnumGUID_Construct(REFCLSID rclsid
, LPCWSTR impl_req
, IEnumCATID
**ret
);
68 /**********************************************************************
69 * File-scope string constants
71 static const WCHAR comcat_keyname
[] = {
72 'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0 };
73 static const WCHAR impl_keyname
[] = {
74 'I','m','p','l','e','m','e','n','t','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
75 static const WCHAR req_keyname
[] = {
76 'R','e','q','u','i','r','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
77 static const WCHAR clsid_keyname
[] = { 'C','L','S','I','D',0 };
80 /**********************************************************************
81 * COMCAT_RegisterClassCategories
83 static HRESULT
COMCAT_RegisterClassCategories(
89 WCHAR keyname
[CHARS_IN_GUID
];
91 HKEY clsid_key
, class_key
, type_key
;
93 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
95 /* Format the class key name. */
96 res
= StringFromGUID2(rclsid
, keyname
, CHARS_IN_GUID
);
97 if (FAILED(res
)) return res
;
99 /* Create (or open) the CLSID key. */
100 res
= create_classes_key(HKEY_CLASSES_ROOT
, clsid_keyname
, KEY_READ
|KEY_WRITE
, &clsid_key
);
101 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
103 /* Create (or open) the class key. */
104 res
= create_classes_key(clsid_key
, keyname
, KEY_READ
|KEY_WRITE
, &class_key
);
105 if (res
== ERROR_SUCCESS
) {
106 /* Create (or open) the category type key. */
107 res
= create_classes_key(class_key
, type
, KEY_READ
|KEY_WRITE
, &type_key
);
108 if (res
== ERROR_SUCCESS
) {
109 for (; cCategories
; --cCategories
, ++rgcatid
) {
112 /* Format the category key name. */
113 res
= StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
);
114 if (FAILED(res
)) continue;
116 /* Do the register. */
117 res
= create_classes_key(type_key
, keyname
, KEY_READ
|KEY_WRITE
, &key
);
118 if (res
== ERROR_SUCCESS
) RegCloseKey(key
);
122 RegCloseKey(class_key
);
124 RegCloseKey(clsid_key
);
129 /**********************************************************************
130 * COMCAT_UnRegisterClassCategories
132 static HRESULT
COMCAT_UnRegisterClassCategories(
136 const CATID
*rgcatid
)
138 WCHAR keyname
[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
142 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
144 /* Format the class category type key name. */
145 res
= StringFromGUID2(rclsid
, keyname
+ 6, CHARS_IN_GUID
);
146 if (FAILED(res
)) return res
;
148 lstrcpyW(keyname
+ 45, type
);
150 /* Open the class category type key. */
151 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
|KEY_WRITE
, &type_key
);
152 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
154 for (; cCategories
; --cCategories
, ++rgcatid
) {
155 /* Format the category key name. */
156 res
= StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
);
157 if (FAILED(res
)) continue;
159 /* Do the unregister. */
160 RegDeleteKeyW(type_key
, keyname
);
162 RegCloseKey(type_key
);
167 /**********************************************************************
168 * COMCAT_GetCategoryDesc
170 static HRESULT
COMCAT_GetCategoryDesc(HKEY key
, LCID lcid
, PWCHAR pszDesc
,
173 static const WCHAR fmt
[] = { '%', 'l', 'X', 0 };
176 DWORD type
, size
= (buf_wchars
- 1) * sizeof(WCHAR
);
178 if (pszDesc
== NULL
) return E_INVALIDARG
;
180 /* FIXME: lcid comparisons are more complex than this! */
181 wsprintfW(valname
, fmt
, lcid
);
182 res
= RegQueryValueExW(key
, valname
, 0, &type
, (LPBYTE
)pszDesc
, &size
);
183 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
) {
184 FIXME("Simplified lcid comparison\n");
185 return CAT_E_NODESCRIPTION
;
187 pszDesc
[size
/ sizeof(WCHAR
)] = 0;
192 /**********************************************************************
193 * COMCAT_PrepareClassCategories
195 static struct class_categories
*COMCAT_PrepareClassCategories(
196 ULONG impl_count
, const CATID
*impl_catids
, ULONG req_count
, const CATID
*req_catids
)
198 struct class_categories
*categories
;
202 size
= sizeof(struct class_categories
) + ((impl_count
+ req_count
)*CHARS_IN_GUID
+ 2)*sizeof(WCHAR
);
203 categories
= HeapAlloc(GetProcessHeap(), 0, size
);
204 if (categories
== NULL
) return categories
;
206 categories
->size
= size
;
207 categories
->impl_offset
= sizeof(struct class_categories
);
208 categories
->req_offset
= categories
->impl_offset
+ (impl_count
*CHARS_IN_GUID
+ 1)*sizeof(WCHAR
);
210 strings
= (WCHAR
*)(categories
+ 1);
211 while (impl_count
--) {
212 StringFromGUID2(impl_catids
++, strings
, CHARS_IN_GUID
);
213 strings
+= CHARS_IN_GUID
;
217 while (req_count
--) {
218 StringFromGUID2(req_catids
++, strings
, CHARS_IN_GUID
);
219 strings
+= CHARS_IN_GUID
;
226 /**********************************************************************
227 * COMCAT_IsClassOfCategories
229 static HRESULT
COMCAT_IsClassOfCategories(
231 struct class_categories
const* categories
)
233 const WCHAR
*impl_strings
, *req_strings
;
239 impl_strings
= (WCHAR
*)((BYTE
*)categories
+ categories
->impl_offset
);
240 req_strings
= (WCHAR
*)((BYTE
*)categories
+ categories
->req_offset
);
242 /* Check that every given category is implemented by class. */
244 res
= open_classes_key(key
, impl_keyname
, KEY_READ
, &subkey
);
245 if (res
!= ERROR_SUCCESS
) return S_FALSE
;
246 for (string
= impl_strings
; *string
; string
+= CHARS_IN_GUID
) {
248 res
= open_classes_key(subkey
, string
, READ_CONTROL
, &catkey
);
249 if (res
!= ERROR_SUCCESS
) {
258 /* Check that all categories required by class are given. */
259 res
= open_classes_key(key
, req_keyname
, KEY_READ
, &subkey
);
260 if (res
== ERROR_SUCCESS
) {
261 for (index
= 0; ; ++index
) {
262 WCHAR keyname
[CHARS_IN_GUID
];
263 DWORD size
= CHARS_IN_GUID
;
265 res
= RegEnumKeyExW(subkey
, index
, keyname
, &size
,
266 NULL
, NULL
, NULL
, NULL
);
267 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
268 if (size
!= CHARS_IN_GUID
-1) continue; /* bogus catid in registry */
269 for (string
= req_strings
; *string
; string
+= CHARS_IN_GUID
)
270 if (!strcmpiW(string
, keyname
)) break;
282 /**********************************************************************
283 * COMCAT_ICatRegister_QueryInterface
285 static HRESULT WINAPI
COMCAT_ICatRegister_QueryInterface(
290 TRACE("%s\n",debugstr_guid(riid
));
292 if (ppvObj
== NULL
) return E_POINTER
;
294 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ICatRegister
)) {
296 ICatRegister_AddRef(iface
);
300 if (IsEqualGUID(riid
, &IID_ICatInformation
)) {
301 *ppvObj
= &COMCAT_ComCatMgr
.ICatInformation_iface
;
302 ICatRegister_AddRef(iface
);
306 return E_NOINTERFACE
;
309 /**********************************************************************
310 * COMCAT_ICatRegister_AddRef
312 static ULONG WINAPI
COMCAT_ICatRegister_AddRef(LPCATREGISTER iface
)
314 return 2; /* non-heap based object */
317 /**********************************************************************
318 * COMCAT_ICatRegister_Release
320 static ULONG WINAPI
COMCAT_ICatRegister_Release(LPCATREGISTER iface
)
322 return 1; /* non-heap based object */
325 /**********************************************************************
326 * COMCAT_ICatRegister_RegisterCategories
328 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterCategories(
338 if (cCategories
&& rgci
== NULL
)
341 /* Create (or open) the component categories key. */
342 res
= create_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
|KEY_WRITE
, &comcat_key
);
343 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
345 for (; cCategories
; --cCategories
, ++rgci
) {
346 static const WCHAR fmt
[] = { '%', 'l', 'X', 0 };
347 WCHAR keyname
[CHARS_IN_GUID
];
351 /* Create (or open) the key for this category. */
352 if (!StringFromGUID2(&rgci
->catid
, keyname
, CHARS_IN_GUID
)) continue;
353 res
= create_classes_key(comcat_key
, keyname
, KEY_READ
|KEY_WRITE
, &cat_key
);
354 if (res
!= ERROR_SUCCESS
) continue;
356 /* Set the value for this locale's description. */
357 wsprintfW(valname
, fmt
, rgci
->lcid
);
358 RegSetValueExW(cat_key
, valname
, 0, REG_SZ
, (const BYTE
*)rgci
->szDescription
,
359 (lstrlenW(rgci
->szDescription
) + 1) * sizeof(WCHAR
));
361 RegCloseKey(cat_key
);
364 RegCloseKey(comcat_key
);
368 /**********************************************************************
369 * COMCAT_ICatRegister_UnRegisterCategories
371 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterCategories(
381 if (cCategories
&& rgcatid
== NULL
)
384 /* Open the component categories key. */
385 res
= open_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
|KEY_WRITE
, &comcat_key
);
386 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
388 for (; cCategories
; --cCategories
, ++rgcatid
) {
389 WCHAR keyname
[CHARS_IN_GUID
];
391 /* Delete the key for this category. */
392 if (!StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
)) continue;
393 RegDeleteKeyW(comcat_key
, keyname
);
396 RegCloseKey(comcat_key
);
400 /**********************************************************************
401 * COMCAT_ICatRegister_RegisterClassImplCategories
403 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassImplCategories(
411 return COMCAT_RegisterClassCategories(
412 rclsid
, impl_keyname
, cCategories
, rgcatid
);
415 /**********************************************************************
416 * COMCAT_ICatRegister_UnRegisterClassImplCategories
418 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassImplCategories(
426 return COMCAT_UnRegisterClassCategories(
427 rclsid
, impl_keyname
, cCategories
, rgcatid
);
430 /**********************************************************************
431 * COMCAT_ICatRegister_RegisterClassReqCategories
433 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassReqCategories(
441 return COMCAT_RegisterClassCategories(
442 rclsid
, req_keyname
, cCategories
, rgcatid
);
445 /**********************************************************************
446 * COMCAT_ICatRegister_UnRegisterClassReqCategories
448 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassReqCategories(
456 return COMCAT_UnRegisterClassCategories(
457 rclsid
, req_keyname
, cCategories
, rgcatid
);
460 /**********************************************************************
461 * COMCAT_ICatInformation_QueryInterface
463 static HRESULT WINAPI
COMCAT_ICatInformation_QueryInterface(
464 LPCATINFORMATION iface
,
468 return ICatRegister_QueryInterface(&COMCAT_ComCatMgr
.ICatRegister_iface
, riid
, ppvObj
);
471 /**********************************************************************
472 * COMCAT_ICatInformation_AddRef
474 static ULONG WINAPI
COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface
)
476 return ICatRegister_AddRef(&COMCAT_ComCatMgr
.ICatRegister_iface
);
479 /**********************************************************************
480 * COMCAT_ICatInformation_Release
482 static ULONG WINAPI
COMCAT_ICatInformation_Release(LPCATINFORMATION iface
)
484 return ICatRegister_Release(&COMCAT_ComCatMgr
.ICatRegister_iface
);
487 /**********************************************************************
488 * COMCAT_ICatInformation_EnumCategories
490 static HRESULT WINAPI
COMCAT_ICatInformation_EnumCategories(
491 LPCATINFORMATION iface
,
493 IEnumCATEGORYINFO
**ppenumCatInfo
)
497 if (ppenumCatInfo
== NULL
) return E_POINTER
;
499 return EnumCATEGORYINFO_Construct(lcid
, ppenumCatInfo
);
502 /**********************************************************************
503 * COMCAT_ICatInformation_GetCategoryDesc
505 static HRESULT WINAPI
COMCAT_ICatInformation_GetCategoryDesc(
506 LPCATINFORMATION iface
,
511 WCHAR keyname
[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
512 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
513 'r', 'i', 'e', 's', '\\', 0 };
517 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid
), lcid
);
519 if (rcatid
== NULL
|| ppszDesc
== NULL
) return E_INVALIDARG
;
521 /* Open the key for this category. */
522 if (!StringFromGUID2(rcatid
, keyname
+ 21, CHARS_IN_GUID
)) return E_FAIL
;
523 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &key
);
524 if (res
!= ERROR_SUCCESS
) return CAT_E_CATIDNOEXIST
;
526 /* Allocate a sensible amount of memory for the description. */
527 *ppszDesc
= CoTaskMemAlloc(128 * sizeof(WCHAR
));
528 if (*ppszDesc
== NULL
) {
530 return E_OUTOFMEMORY
;
533 /* Get the description, and make sure it's null terminated. */
534 res
= COMCAT_GetCategoryDesc(key
, lcid
, *ppszDesc
, 128);
537 CoTaskMemFree(*ppszDesc
);
544 /**********************************************************************
545 * COMCAT_ICatInformation_EnumClassesOfCategories
547 static HRESULT WINAPI
COMCAT_ICatInformation_EnumClassesOfCategories(
548 LPCATINFORMATION iface
,
553 LPENUMCLSID
*ppenumCLSID
)
555 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
;
573 hr
= CLSIDEnumGUID_Construct(categories
, ppenumCLSID
);
576 HeapFree(GetProcessHeap(), 0, categories
);
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
;
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, CHARS_IN_GUID
);
613 if (FAILED(res
)) return res
;
615 categories
= COMCAT_PrepareClassCategories(cImplemented
, rgcatidImpl
,
616 cRequired
, rgcatidReq
);
617 if (categories
== NULL
) return E_OUTOFMEMORY
;
619 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, 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
[] = { '\\', '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 return CATIDEnumGUID_Construct(rclsid
, postfix
, ppenumCATID
);
650 /**********************************************************************
651 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
653 static HRESULT WINAPI
COMCAT_ICatInformation_EnumReqCategoriesOfClass(
654 LPCATINFORMATION iface
,
656 LPENUMCATID
*ppenumCATID
)
658 static const WCHAR postfix
[] = { '\\', '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 return CATIDEnumGUID_Construct(rclsid
, postfix
, ppenumCATID
);
670 /**********************************************************************
671 * COMCAT_ICatRegister_Vtbl
673 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
=
675 COMCAT_ICatRegister_QueryInterface
,
676 COMCAT_ICatRegister_AddRef
,
677 COMCAT_ICatRegister_Release
,
678 COMCAT_ICatRegister_RegisterCategories
,
679 COMCAT_ICatRegister_UnRegisterCategories
,
680 COMCAT_ICatRegister_RegisterClassImplCategories
,
681 COMCAT_ICatRegister_UnRegisterClassImplCategories
,
682 COMCAT_ICatRegister_RegisterClassReqCategories
,
683 COMCAT_ICatRegister_UnRegisterClassReqCategories
687 /**********************************************************************
688 * COMCAT_ICatInformation_Vtbl
690 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl
=
692 COMCAT_ICatInformation_QueryInterface
,
693 COMCAT_ICatInformation_AddRef
,
694 COMCAT_ICatInformation_Release
,
695 COMCAT_ICatInformation_EnumCategories
,
696 COMCAT_ICatInformation_GetCategoryDesc
,
697 COMCAT_ICatInformation_EnumClassesOfCategories
,
698 COMCAT_ICatInformation_IsClassOfCategories
,
699 COMCAT_ICatInformation_EnumImplCategoriesOfClass
,
700 COMCAT_ICatInformation_EnumReqCategoriesOfClass
703 HRESULT WINAPI
ComCat_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, void **ppvObj
)
706 TRACE("%s\n",debugstr_guid(riid
));
708 if (ppvObj
== NULL
) return E_POINTER
;
710 /* Don't support aggregation (Windows doesn't) */
711 if (pUnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
713 res
= ICatRegister_QueryInterface(&COMCAT_ComCatMgr
.ICatRegister_iface
, riid
, ppvObj
);
714 if (SUCCEEDED(res
)) {
718 return CLASS_E_CLASSNOTAVAILABLE
;
721 /**********************************************************************
722 * IEnumCATEGORYINFO implementation
724 * This implementation is not thread-safe. The manager itself is, but
725 * I can't imagine a valid use of an enumerator in several threads.
729 IEnumCATEGORYINFO IEnumCATEGORYINFO_iface
;
734 } IEnumCATEGORYINFOImpl
;
736 static inline IEnumCATEGORYINFOImpl
*impl_from_IEnumCATEGORYINFO(IEnumCATEGORYINFO
*iface
)
738 return CONTAINING_RECORD(iface
, IEnumCATEGORYINFOImpl
, IEnumCATEGORYINFO_iface
);
741 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_AddRef(IEnumCATEGORYINFO
*iface
)
743 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
747 return InterlockedIncrement(&This
->ref
);
750 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_QueryInterface(
751 IEnumCATEGORYINFO
*iface
,
755 TRACE("%s\n",debugstr_guid(riid
));
757 if (ppvObj
== NULL
) return E_POINTER
;
759 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
760 IsEqualGUID(riid
, &IID_IEnumCATEGORYINFO
))
763 COMCAT_IEnumCATEGORYINFO_AddRef(iface
);
767 return E_NOINTERFACE
;
770 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_Release(IEnumCATEGORYINFO
*iface
)
772 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
777 ref
= InterlockedDecrement(&This
->ref
);
779 if (This
->key
) RegCloseKey(This
->key
);
780 HeapFree(GetProcessHeap(), 0, This
);
786 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Next(
787 IEnumCATEGORYINFO
*iface
,
792 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
797 if (rgelt
== NULL
) return E_POINTER
;
799 if (This
->key
) while (fetched
< celt
) {
802 WCHAR catid
[CHARS_IN_GUID
];
803 DWORD cName
= CHARS_IN_GUID
;
806 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
807 NULL
, NULL
, NULL
, NULL
);
808 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
809 ++(This
->next_index
);
811 hr
= CLSIDFromString(catid
, &rgelt
->catid
);
812 if (FAILED(hr
)) continue;
814 res
= open_classes_key(This
->key
, catid
, KEY_READ
, &subkey
);
815 if (res
!= ERROR_SUCCESS
) continue;
817 hr
= COMCAT_GetCategoryDesc(subkey
, This
->lcid
,
818 rgelt
->szDescription
, 128);
820 if (FAILED(hr
)) continue;
822 rgelt
->lcid
= This
->lcid
;
827 if (pceltFetched
) *pceltFetched
= fetched
;
828 return fetched
== celt
? S_OK
: S_FALSE
;
831 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Skip(
832 IEnumCATEGORYINFO
*iface
,
835 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
839 This
->next_index
+= celt
;
840 /* This should return S_FALSE when there aren't celt elems to skip. */
844 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Reset(IEnumCATEGORYINFO
*iface
)
846 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
850 This
->next_index
= 0;
854 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Clone(
855 IEnumCATEGORYINFO
*iface
,
856 IEnumCATEGORYINFO
**ppenum
)
858 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
859 static const WCHAR keyname
[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
860 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
861 'r', 'i', 'e', 's', 0 };
862 IEnumCATEGORYINFOImpl
*new_this
;
866 if (ppenum
== NULL
) return E_POINTER
;
868 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
869 if (new_this
== NULL
) return E_OUTOFMEMORY
;
871 new_this
->IEnumCATEGORYINFO_iface
= This
->IEnumCATEGORYINFO_iface
;
873 new_this
->lcid
= This
->lcid
;
874 /* FIXME: could we more efficiently use DuplicateHandle? */
875 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &new_this
->key
);
876 new_this
->next_index
= This
->next_index
;
878 *ppenum
= &new_this
->IEnumCATEGORYINFO_iface
;
882 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl
=
884 COMCAT_IEnumCATEGORYINFO_QueryInterface
,
885 COMCAT_IEnumCATEGORYINFO_AddRef
,
886 COMCAT_IEnumCATEGORYINFO_Release
,
887 COMCAT_IEnumCATEGORYINFO_Next
,
888 COMCAT_IEnumCATEGORYINFO_Skip
,
889 COMCAT_IEnumCATEGORYINFO_Reset
,
890 COMCAT_IEnumCATEGORYINFO_Clone
893 static HRESULT
EnumCATEGORYINFO_Construct(LCID lcid
, IEnumCATEGORYINFO
**ret
)
895 static const WCHAR keyname
[] = {'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0};
896 IEnumCATEGORYINFOImpl
*This
;
900 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
901 if (!This
) return E_OUTOFMEMORY
;
903 This
->IEnumCATEGORYINFO_iface
.lpVtbl
= &COMCAT_IEnumCATEGORYINFO_Vtbl
;
906 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
908 *ret
= &This
->IEnumCATEGORYINFO_iface
;
912 /**********************************************************************
913 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
915 * This implementation is not thread-safe. The manager itself is, but
916 * I can't imagine a valid use of an enumerator in several threads.
920 IEnumGUID IEnumGUID_iface
;
922 struct class_categories
*categories
;
925 } CLSID_IEnumGUIDImpl
;
927 static inline CLSID_IEnumGUIDImpl
*impl_from_IEnumCLSID(IEnumGUID
*iface
)
929 return CONTAINING_RECORD(iface
, CLSID_IEnumGUIDImpl
, IEnumGUID_iface
);
932 static HRESULT WINAPI
CLSIDEnumGUID_QueryInterface(
937 TRACE("%s\n",debugstr_guid(riid
));
939 if (ppvObj
== NULL
) return E_POINTER
;
941 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
942 IsEqualGUID(riid
, &IID_IEnumGUID
))
945 IEnumGUID_AddRef(iface
);
949 return E_NOINTERFACE
;
952 static ULONG WINAPI
CLSIDEnumGUID_AddRef(IEnumGUID
*iface
)
954 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
957 return InterlockedIncrement(&This
->ref
);
960 static ULONG WINAPI
CLSIDEnumGUID_Release(IEnumGUID
*iface
)
962 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
967 ref
= InterlockedDecrement(&This
->ref
);
969 if (This
->key
) RegCloseKey(This
->key
);
970 HeapFree(GetProcessHeap(), 0, This
->categories
);
971 HeapFree(GetProcessHeap(), 0, This
);
977 static HRESULT WINAPI
CLSIDEnumGUID_Next(
983 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
988 if (rgelt
== NULL
) return E_POINTER
;
990 if (This
->key
) while (fetched
< celt
) {
993 WCHAR clsid
[CHARS_IN_GUID
];
994 DWORD cName
= CHARS_IN_GUID
;
997 res
= RegEnumKeyExW(This
->key
, This
->next_index
, clsid
, &cName
,
998 NULL
, NULL
, NULL
, NULL
);
999 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1000 ++(This
->next_index
);
1002 hr
= CLSIDFromString(clsid
, rgelt
);
1003 if (FAILED(hr
)) continue;
1005 res
= open_classes_key(This
->key
, clsid
, KEY_READ
, &subkey
);
1006 if (res
!= ERROR_SUCCESS
) continue;
1008 hr
= COMCAT_IsClassOfCategories(subkey
, This
->categories
);
1009 RegCloseKey(subkey
);
1010 if (hr
!= S_OK
) continue;
1016 if (pceltFetched
) *pceltFetched
= fetched
;
1017 return fetched
== celt
? S_OK
: S_FALSE
;
1020 static HRESULT WINAPI
CLSIDEnumGUID_Skip(
1024 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1028 This
->next_index
+= celt
;
1029 FIXME("Never returns S_FALSE\n");
1033 static HRESULT WINAPI
CLSIDEnumGUID_Reset(IEnumGUID
*iface
)
1035 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1039 This
->next_index
= 0;
1043 static HRESULT WINAPI
CLSIDEnumGUID_Clone(
1047 static const WCHAR keynameW
[] = {'C','L','S','I','D',0};
1048 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1049 CLSID_IEnumGUIDImpl
*cloned
;
1051 TRACE("(%p)->(%p)\n", This
, ppenum
);
1053 if (ppenum
== NULL
) return E_POINTER
;
1057 cloned
= HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID_IEnumGUIDImpl
));
1058 if (cloned
== NULL
) return E_OUTOFMEMORY
;
1060 cloned
->IEnumGUID_iface
.lpVtbl
= This
->IEnumGUID_iface
.lpVtbl
;
1063 cloned
->categories
= HeapAlloc(GetProcessHeap(), 0, This
->categories
->size
);
1064 if (cloned
->categories
== NULL
) {
1065 HeapFree(GetProcessHeap(), 0, cloned
);
1066 return E_OUTOFMEMORY
;
1068 memcpy(cloned
->categories
, This
->categories
, This
->categories
->size
);
1071 open_classes_key(HKEY_CLASSES_ROOT
, keynameW
, KEY_READ
, &cloned
->key
);
1072 cloned
->next_index
= This
->next_index
;
1074 *ppenum
= &cloned
->IEnumGUID_iface
;
1078 static const IEnumGUIDVtbl CLSIDEnumGUIDVtbl
=
1080 CLSIDEnumGUID_QueryInterface
,
1081 CLSIDEnumGUID_AddRef
,
1082 CLSIDEnumGUID_Release
,
1085 CLSIDEnumGUID_Reset
,
1089 static HRESULT
CLSIDEnumGUID_Construct(struct class_categories
*categories
, IEnumCLSID
**ret
)
1091 static const WCHAR keyname
[] = {'C','L','S','I','D',0};
1092 CLSID_IEnumGUIDImpl
*This
;
1096 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLSID_IEnumGUIDImpl
));
1097 if (!This
) return E_OUTOFMEMORY
;
1099 This
->IEnumGUID_iface
.lpVtbl
= &CLSIDEnumGUIDVtbl
;
1101 This
->categories
= categories
;
1102 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
1104 *ret
= &This
->IEnumGUID_iface
;
1109 /**********************************************************************
1110 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1112 * This implementation is not thread-safe. The manager itself is, but
1113 * I can't imagine a valid use of an enumerator in several threads.
1117 IEnumGUID IEnumGUID_iface
;
1122 } CATID_IEnumGUIDImpl
;
1124 static inline CATID_IEnumGUIDImpl
*impl_from_IEnumCATID(IEnumGUID
*iface
)
1126 return CONTAINING_RECORD(iface
, CATID_IEnumGUIDImpl
, IEnumGUID_iface
);
1129 static HRESULT WINAPI
CATIDEnumGUID_QueryInterface(
1134 TRACE("%s\n",debugstr_guid(riid
));
1136 if (ppvObj
== NULL
) return E_POINTER
;
1138 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
1139 IsEqualGUID(riid
, &IID_IEnumGUID
))
1142 IEnumGUID_AddRef(iface
);
1146 return E_NOINTERFACE
;
1149 static ULONG WINAPI
CATIDEnumGUID_AddRef(IEnumGUID
*iface
)
1151 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1154 return InterlockedIncrement(&This
->ref
);
1157 static ULONG WINAPI
CATIDEnumGUID_Release(IEnumGUID
*iface
)
1159 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1164 ref
= InterlockedDecrement(&This
->ref
);
1166 if (This
->key
) RegCloseKey(This
->key
);
1167 HeapFree(GetProcessHeap(), 0, This
);
1173 static HRESULT WINAPI
CATIDEnumGUID_Next(
1177 ULONG
*pceltFetched
)
1179 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1184 if (rgelt
== NULL
) return E_POINTER
;
1186 if (This
->key
) while (fetched
< celt
) {
1189 WCHAR catid
[CHARS_IN_GUID
];
1190 DWORD cName
= CHARS_IN_GUID
;
1192 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
1193 NULL
, NULL
, NULL
, NULL
);
1194 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1195 ++(This
->next_index
);
1197 hr
= CLSIDFromString(catid
, rgelt
);
1198 if (FAILED(hr
)) continue;
1204 if (pceltFetched
) *pceltFetched
= fetched
;
1205 return fetched
== celt
? S_OK
: S_FALSE
;
1208 static HRESULT WINAPI
CATIDEnumGUID_Skip(
1212 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1216 This
->next_index
+= celt
;
1217 FIXME("Never returns S_FALSE\n");
1221 static HRESULT WINAPI
CATIDEnumGUID_Reset(IEnumGUID
*iface
)
1223 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1227 This
->next_index
= 0;
1231 static HRESULT WINAPI
CATIDEnumGUID_Clone(
1235 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1236 CATID_IEnumGUIDImpl
*new_this
;
1240 if (ppenum
== NULL
) return E_POINTER
;
1242 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1243 if (new_this
== NULL
) return E_OUTOFMEMORY
;
1245 new_this
->IEnumGUID_iface
.lpVtbl
= This
->IEnumGUID_iface
.lpVtbl
;
1247 lstrcpyW(new_this
->keyname
, This
->keyname
);
1248 /* FIXME: could we more efficiently use DuplicateHandle? */
1249 open_classes_key(HKEY_CLASSES_ROOT
, new_this
->keyname
, KEY_READ
, &new_this
->key
);
1250 new_this
->next_index
= This
->next_index
;
1252 *ppenum
= &new_this
->IEnumGUID_iface
;
1256 static const IEnumGUIDVtbl CATIDEnumGUIDVtbl
=
1258 CATIDEnumGUID_QueryInterface
,
1259 CATIDEnumGUID_AddRef
,
1260 CATIDEnumGUID_Release
,
1263 CATIDEnumGUID_Reset
,
1267 static HRESULT
CATIDEnumGUID_Construct(REFCLSID rclsid
, LPCWSTR postfix
, IEnumGUID
**ret
)
1269 static const WCHAR prefixW
[] = {'C','L','S','I','D','\\',0};
1270 WCHAR keyname
[100], clsidW
[CHARS_IN_GUID
];
1271 CATID_IEnumGUIDImpl
*This
;
1275 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1276 if (!This
) return E_OUTOFMEMORY
;
1278 StringFromGUID2(rclsid
, clsidW
, CHARS_IN_GUID
);
1280 This
->IEnumGUID_iface
.lpVtbl
= &CATIDEnumGUIDVtbl
;
1282 strcpyW(keyname
, prefixW
);
1283 strcatW(keyname
, clsidW
);
1284 strcatW(keyname
, postfix
);
1286 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
1288 *ret
= &This
->IEnumGUID_iface
;