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/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
40 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
;
41 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl
;
45 ICatRegister ICatRegister_iface
;
46 ICatInformation ICatInformation_iface
;
49 /* static ComCatMgr instance */
50 static ComCatMgrImpl COMCAT_ComCatMgr
=
52 { &COMCAT_ICatRegister_Vtbl
},
53 { &COMCAT_ICatInformation_Vtbl
}
56 struct class_categories
58 ULONG size
; /* total length, including structure itself */
63 static HRESULT
EnumCATEGORYINFO_Construct(LCID lcid
, IEnumCATEGORYINFO
**ret
);
64 static HRESULT
CLSIDEnumGUID_Construct(struct class_categories
*class_categories
, IEnumCLSID
**ret
);
65 static HRESULT
CATIDEnumGUID_Construct(REFCLSID rclsid
, LPCWSTR impl_req
, IEnumCATID
**ret
);
67 /**********************************************************************
68 * File-scope string constants
70 static const WCHAR comcat_keyname
[] = L
"Component Categories";
71 static const WCHAR impl_keyname
[] = L
"Implemented Categories";
72 static const WCHAR req_keyname
[] = L
"Required Categories";
74 /**********************************************************************
75 * COMCAT_RegisterClassCategories
77 static HRESULT
COMCAT_RegisterClassCategories(
83 WCHAR keyname
[CHARS_IN_GUID
];
85 HKEY clsid_key
, class_key
, type_key
;
87 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
89 /* Format the class key name. */
90 res
= StringFromGUID2(rclsid
, keyname
, CHARS_IN_GUID
);
91 if (FAILED(res
)) return res
;
93 /* Create (or open) the CLSID key. */
94 res
= create_classes_key(HKEY_CLASSES_ROOT
, L
"CLSID", KEY_READ
|KEY_WRITE
, &clsid_key
);
95 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
97 /* Create (or open) the class key. */
98 res
= create_classes_key(clsid_key
, keyname
, KEY_READ
|KEY_WRITE
, &class_key
);
99 if (res
== ERROR_SUCCESS
) {
100 /* Create (or open) the category type key. */
101 res
= create_classes_key(class_key
, type
, KEY_READ
|KEY_WRITE
, &type_key
);
102 if (res
== ERROR_SUCCESS
) {
103 for (; cCategories
; --cCategories
, ++rgcatid
) {
106 /* Format the category key name. */
107 res
= StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
);
108 if (FAILED(res
)) continue;
110 /* Do the register. */
111 res
= create_classes_key(type_key
, keyname
, KEY_READ
|KEY_WRITE
, &key
);
112 if (res
== ERROR_SUCCESS
) RegCloseKey(key
);
116 RegCloseKey(class_key
);
118 RegCloseKey(clsid_key
);
123 /**********************************************************************
124 * COMCAT_UnRegisterClassCategories
126 static HRESULT
COMCAT_UnRegisterClassCategories(
130 const CATID
*rgcatid
)
132 WCHAR keyname
[68] = L
"CLSID\\";
136 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
138 /* Format the class category type key name. */
139 res
= StringFromGUID2(rclsid
, keyname
+ 6, CHARS_IN_GUID
);
140 if (FAILED(res
)) return res
;
142 lstrcpyW(keyname
+ 45, type
);
144 /* Open the class category type key. */
145 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
|KEY_WRITE
, &type_key
);
146 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
148 for (; cCategories
; --cCategories
, ++rgcatid
) {
149 /* Format the category key name. */
150 res
= StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
);
151 if (FAILED(res
)) continue;
153 /* Do the unregister. */
154 RegDeleteKeyW(type_key
, keyname
);
156 RegCloseKey(type_key
);
161 /**********************************************************************
162 * COMCAT_GetCategoryDesc
164 static HRESULT
COMCAT_GetCategoryDesc(HKEY key
, LCID lcid
, PWCHAR pszDesc
,
169 DWORD type
, size
= (buf_wchars
- 1) * sizeof(WCHAR
);
171 if (pszDesc
== NULL
) return E_INVALIDARG
;
173 /* FIXME: lcid comparisons are more complex than this! */
174 wsprintfW(valname
, L
"%lX", lcid
);
175 res
= RegQueryValueExW(key
, valname
, 0, &type
, (LPBYTE
)pszDesc
, &size
);
176 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
) {
177 FIXME("Simplified lcid comparison\n");
178 return CAT_E_NODESCRIPTION
;
180 pszDesc
[size
/ sizeof(WCHAR
)] = 0;
185 /**********************************************************************
186 * COMCAT_PrepareClassCategories
188 static struct class_categories
*COMCAT_PrepareClassCategories(
189 ULONG impl_count
, const CATID
*impl_catids
, ULONG req_count
, const CATID
*req_catids
)
191 struct class_categories
*categories
;
195 size
= sizeof(struct class_categories
) + ((impl_count
+ req_count
)*CHARS_IN_GUID
+ 2)*sizeof(WCHAR
);
196 categories
= HeapAlloc(GetProcessHeap(), 0, size
);
197 if (categories
== NULL
) return categories
;
199 categories
->size
= size
;
200 categories
->impl_offset
= sizeof(struct class_categories
);
201 categories
->req_offset
= categories
->impl_offset
+ (impl_count
*CHARS_IN_GUID
+ 1)*sizeof(WCHAR
);
203 strings
= (WCHAR
*)(categories
+ 1);
204 while (impl_count
--) {
205 StringFromGUID2(impl_catids
++, strings
, CHARS_IN_GUID
);
206 strings
+= CHARS_IN_GUID
;
210 while (req_count
--) {
211 StringFromGUID2(req_catids
++, strings
, CHARS_IN_GUID
);
212 strings
+= CHARS_IN_GUID
;
219 /**********************************************************************
220 * COMCAT_IsClassOfCategories
222 static HRESULT
COMCAT_IsClassOfCategories(
224 struct class_categories
const* categories
)
226 const WCHAR
*impl_strings
, *req_strings
;
232 impl_strings
= (WCHAR
*)((BYTE
*)categories
+ categories
->impl_offset
);
233 req_strings
= (WCHAR
*)((BYTE
*)categories
+ categories
->req_offset
);
235 /* Check that every given category is implemented by class. */
237 res
= open_classes_key(key
, impl_keyname
, KEY_READ
, &subkey
);
238 if (res
!= ERROR_SUCCESS
) return S_FALSE
;
239 for (string
= impl_strings
; *string
; string
+= CHARS_IN_GUID
) {
241 res
= open_classes_key(subkey
, string
, READ_CONTROL
, &catkey
);
242 if (res
!= ERROR_SUCCESS
) {
251 /* Check that all categories required by class are given. */
252 res
= open_classes_key(key
, req_keyname
, KEY_READ
, &subkey
);
253 if (res
== ERROR_SUCCESS
) {
254 for (index
= 0; ; ++index
) {
255 WCHAR keyname
[CHARS_IN_GUID
];
256 DWORD size
= CHARS_IN_GUID
;
258 res
= RegEnumKeyExW(subkey
, index
, keyname
, &size
,
259 NULL
, NULL
, NULL
, NULL
);
260 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
261 if (size
!= CHARS_IN_GUID
-1) continue; /* bogus catid in registry */
262 for (string
= req_strings
; *string
; string
+= CHARS_IN_GUID
)
263 if (!wcsicmp(string
, keyname
)) break;
275 /**********************************************************************
276 * COMCAT_ICatRegister_QueryInterface
278 static HRESULT WINAPI
COMCAT_ICatRegister_QueryInterface(
283 TRACE("%s\n",debugstr_guid(riid
));
285 if (ppvObj
== NULL
) return E_POINTER
;
287 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ICatRegister
)) {
289 ICatRegister_AddRef(iface
);
293 if (IsEqualGUID(riid
, &IID_ICatInformation
)) {
294 *ppvObj
= &COMCAT_ComCatMgr
.ICatInformation_iface
;
295 ICatRegister_AddRef(iface
);
299 return E_NOINTERFACE
;
302 /**********************************************************************
303 * COMCAT_ICatRegister_AddRef
305 static ULONG WINAPI
COMCAT_ICatRegister_AddRef(LPCATREGISTER iface
)
307 return 2; /* non-heap based object */
310 /**********************************************************************
311 * COMCAT_ICatRegister_Release
313 static ULONG WINAPI
COMCAT_ICatRegister_Release(LPCATREGISTER iface
)
315 return 1; /* non-heap based object */
318 /**********************************************************************
319 * COMCAT_ICatRegister_RegisterCategories
321 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterCategories(
331 if (cCategories
&& rgci
== NULL
)
334 /* Create (or open) the component categories key. */
335 res
= create_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
|KEY_WRITE
, &comcat_key
);
336 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
338 for (; cCategories
; --cCategories
, ++rgci
)
340 WCHAR keyname
[CHARS_IN_GUID
];
344 /* Create (or open) the key for this category. */
345 if (!StringFromGUID2(&rgci
->catid
, keyname
, CHARS_IN_GUID
)) continue;
346 res
= create_classes_key(comcat_key
, keyname
, KEY_READ
|KEY_WRITE
, &cat_key
);
347 if (res
!= ERROR_SUCCESS
) continue;
349 /* Set the value for this locale's description. */
350 wsprintfW(valname
, L
"%lX", rgci
->lcid
);
351 RegSetValueExW(cat_key
, valname
, 0, REG_SZ
, (const BYTE
*)rgci
->szDescription
,
352 (lstrlenW(rgci
->szDescription
) + 1) * sizeof(WCHAR
));
354 RegCloseKey(cat_key
);
357 RegCloseKey(comcat_key
);
361 /**********************************************************************
362 * COMCAT_ICatRegister_UnRegisterCategories
364 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterCategories(
374 if (cCategories
&& rgcatid
== NULL
)
377 /* Open the component categories key. */
378 res
= open_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
|KEY_WRITE
, &comcat_key
);
379 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
381 for (; cCategories
; --cCategories
, ++rgcatid
) {
382 WCHAR keyname
[CHARS_IN_GUID
];
384 /* Delete the key for this category. */
385 if (!StringFromGUID2(rgcatid
, keyname
, CHARS_IN_GUID
)) continue;
386 RegDeleteKeyW(comcat_key
, keyname
);
389 RegCloseKey(comcat_key
);
393 /**********************************************************************
394 * COMCAT_ICatRegister_RegisterClassImplCategories
396 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassImplCategories(
404 return COMCAT_RegisterClassCategories(
405 rclsid
, impl_keyname
, cCategories
, rgcatid
);
408 /**********************************************************************
409 * COMCAT_ICatRegister_UnRegisterClassImplCategories
411 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassImplCategories(
419 return COMCAT_UnRegisterClassCategories(
420 rclsid
, impl_keyname
, cCategories
, rgcatid
);
423 /**********************************************************************
424 * COMCAT_ICatRegister_RegisterClassReqCategories
426 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterClassReqCategories(
434 return COMCAT_RegisterClassCategories(
435 rclsid
, req_keyname
, cCategories
, rgcatid
);
438 /**********************************************************************
439 * COMCAT_ICatRegister_UnRegisterClassReqCategories
441 static HRESULT WINAPI
COMCAT_ICatRegister_UnRegisterClassReqCategories(
449 return COMCAT_UnRegisterClassCategories(
450 rclsid
, req_keyname
, cCategories
, rgcatid
);
453 /**********************************************************************
454 * COMCAT_ICatInformation_QueryInterface
456 static HRESULT WINAPI
COMCAT_ICatInformation_QueryInterface(
457 LPCATINFORMATION iface
,
461 return ICatRegister_QueryInterface(&COMCAT_ComCatMgr
.ICatRegister_iface
, riid
, ppvObj
);
464 /**********************************************************************
465 * COMCAT_ICatInformation_AddRef
467 static ULONG WINAPI
COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface
)
469 return ICatRegister_AddRef(&COMCAT_ComCatMgr
.ICatRegister_iface
);
472 /**********************************************************************
473 * COMCAT_ICatInformation_Release
475 static ULONG WINAPI
COMCAT_ICatInformation_Release(LPCATINFORMATION iface
)
477 return ICatRegister_Release(&COMCAT_ComCatMgr
.ICatRegister_iface
);
480 /**********************************************************************
481 * COMCAT_ICatInformation_EnumCategories
483 static HRESULT WINAPI
COMCAT_ICatInformation_EnumCategories(
484 LPCATINFORMATION iface
,
486 IEnumCATEGORYINFO
**ppenumCatInfo
)
490 if (ppenumCatInfo
== NULL
) return E_POINTER
;
492 return EnumCATEGORYINFO_Construct(lcid
, ppenumCatInfo
);
495 /**********************************************************************
496 * COMCAT_ICatInformation_GetCategoryDesc
498 static HRESULT WINAPI
COMCAT_ICatInformation_GetCategoryDesc(
499 LPCATINFORMATION iface
,
504 WCHAR keyname
[60] = L
"Component Categories\\";
508 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid
), lcid
);
510 if (rcatid
== NULL
|| ppszDesc
== NULL
) return E_INVALIDARG
;
512 /* Open the key for this category. */
513 if (!StringFromGUID2(rcatid
, keyname
+ 21, CHARS_IN_GUID
)) return E_FAIL
;
514 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &key
);
515 if (res
!= ERROR_SUCCESS
) return CAT_E_CATIDNOEXIST
;
517 /* Allocate a sensible amount of memory for the description. */
518 *ppszDesc
= CoTaskMemAlloc(128 * sizeof(WCHAR
));
519 if (*ppszDesc
== NULL
) {
521 return E_OUTOFMEMORY
;
524 /* Get the description, and make sure it's null terminated. */
525 res
= COMCAT_GetCategoryDesc(key
, lcid
, *ppszDesc
, 128);
528 CoTaskMemFree(*ppszDesc
);
535 /**********************************************************************
536 * COMCAT_ICatInformation_EnumClassesOfCategories
538 static HRESULT WINAPI
COMCAT_ICatInformation_EnumClassesOfCategories(
539 LPCATINFORMATION iface
,
544 LPENUMCLSID
*ppenumCLSID
)
546 struct class_categories
*categories
;
551 if (cImplemented
== (ULONG
)-1)
553 if (cRequired
== (ULONG
)-1)
556 if (ppenumCLSID
== NULL
||
557 (cImplemented
&& rgcatidImpl
== NULL
) ||
558 (cRequired
&& rgcatidReq
== NULL
)) return E_POINTER
;
560 categories
= COMCAT_PrepareClassCategories(cImplemented
, rgcatidImpl
,
561 cRequired
, rgcatidReq
);
562 if (categories
== NULL
) return E_OUTOFMEMORY
;
564 hr
= CLSIDEnumGUID_Construct(categories
, ppenumCLSID
);
567 HeapFree(GetProcessHeap(), 0, categories
);
574 /**********************************************************************
575 * COMCAT_ICatInformation_IsClassOfCategories
577 static HRESULT WINAPI
COMCAT_ICatInformation_IsClassOfCategories(
578 LPCATINFORMATION iface
,
585 WCHAR keyname
[45] = L
"CLSID\\";
587 struct class_categories
*categories
;
592 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid
),cImplemented
);
593 for (count
= 0; count
< cImplemented
; ++count
)
594 TRACE(" %s\n",debugstr_guid(&rgcatidImpl
[count
]));
595 TRACE("Required %u\n",cRequired
);
596 for (count
= 0; count
< cRequired
; ++count
)
597 TRACE(" %s\n",debugstr_guid(&rgcatidReq
[count
]));
600 if ((cImplemented
&& rgcatidImpl
== NULL
) ||
601 (cRequired
&& rgcatidReq
== NULL
)) return E_POINTER
;
603 res
= StringFromGUID2(rclsid
, keyname
+ 6, CHARS_IN_GUID
);
604 if (FAILED(res
)) return res
;
606 categories
= COMCAT_PrepareClassCategories(cImplemented
, rgcatidImpl
,
607 cRequired
, rgcatidReq
);
608 if (categories
== NULL
) return E_OUTOFMEMORY
;
610 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &key
);
611 if (res
== ERROR_SUCCESS
) {
612 res
= COMCAT_IsClassOfCategories(key
, categories
);
614 } else res
= S_FALSE
;
616 HeapFree(GetProcessHeap(), 0, categories
);
621 /**********************************************************************
622 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
624 static HRESULT WINAPI
COMCAT_ICatInformation_EnumImplCategoriesOfClass(
625 LPCATINFORMATION iface
,
627 LPENUMCATID
*ppenumCATID
)
629 TRACE("%s\n",debugstr_guid(rclsid
));
631 if (rclsid
== NULL
|| ppenumCATID
== NULL
)
634 return CATIDEnumGUID_Construct(rclsid
, L
"\\Implemented Categories", ppenumCATID
);
637 /**********************************************************************
638 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
640 static HRESULT WINAPI
COMCAT_ICatInformation_EnumReqCategoriesOfClass(
641 LPCATINFORMATION iface
,
643 LPENUMCATID
*ppenumCATID
)
645 TRACE("%s\n",debugstr_guid(rclsid
));
647 if (rclsid
== NULL
|| ppenumCATID
== NULL
)
650 return CATIDEnumGUID_Construct(rclsid
, L
"\\Required Categories", ppenumCATID
);
653 /**********************************************************************
654 * COMCAT_ICatRegister_Vtbl
656 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
=
658 COMCAT_ICatRegister_QueryInterface
,
659 COMCAT_ICatRegister_AddRef
,
660 COMCAT_ICatRegister_Release
,
661 COMCAT_ICatRegister_RegisterCategories
,
662 COMCAT_ICatRegister_UnRegisterCategories
,
663 COMCAT_ICatRegister_RegisterClassImplCategories
,
664 COMCAT_ICatRegister_UnRegisterClassImplCategories
,
665 COMCAT_ICatRegister_RegisterClassReqCategories
,
666 COMCAT_ICatRegister_UnRegisterClassReqCategories
670 /**********************************************************************
671 * COMCAT_ICatInformation_Vtbl
673 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl
=
675 COMCAT_ICatInformation_QueryInterface
,
676 COMCAT_ICatInformation_AddRef
,
677 COMCAT_ICatInformation_Release
,
678 COMCAT_ICatInformation_EnumCategories
,
679 COMCAT_ICatInformation_GetCategoryDesc
,
680 COMCAT_ICatInformation_EnumClassesOfCategories
,
681 COMCAT_ICatInformation_IsClassOfCategories
,
682 COMCAT_ICatInformation_EnumImplCategoriesOfClass
,
683 COMCAT_ICatInformation_EnumReqCategoriesOfClass
686 HRESULT WINAPI
ComCat_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, void **ppvObj
)
689 TRACE("%s\n",debugstr_guid(riid
));
691 if (ppvObj
== NULL
) return E_POINTER
;
693 /* Don't support aggregation (Windows doesn't) */
694 if (pUnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
696 res
= ICatRegister_QueryInterface(&COMCAT_ComCatMgr
.ICatRegister_iface
, riid
, ppvObj
);
697 if (SUCCEEDED(res
)) {
701 return CLASS_E_CLASSNOTAVAILABLE
;
704 /**********************************************************************
705 * IEnumCATEGORYINFO implementation
707 * This implementation is not thread-safe. The manager itself is, but
708 * I can't imagine a valid use of an enumerator in several threads.
712 IEnumCATEGORYINFO IEnumCATEGORYINFO_iface
;
717 } IEnumCATEGORYINFOImpl
;
719 static inline IEnumCATEGORYINFOImpl
*impl_from_IEnumCATEGORYINFO(IEnumCATEGORYINFO
*iface
)
721 return CONTAINING_RECORD(iface
, IEnumCATEGORYINFOImpl
, IEnumCATEGORYINFO_iface
);
724 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_AddRef(IEnumCATEGORYINFO
*iface
)
726 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
730 return InterlockedIncrement(&This
->ref
);
733 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_QueryInterface(
734 IEnumCATEGORYINFO
*iface
,
738 TRACE("%s\n",debugstr_guid(riid
));
740 if (ppvObj
== NULL
) return E_POINTER
;
742 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
743 IsEqualGUID(riid
, &IID_IEnumCATEGORYINFO
))
746 COMCAT_IEnumCATEGORYINFO_AddRef(iface
);
750 return E_NOINTERFACE
;
753 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_Release(IEnumCATEGORYINFO
*iface
)
755 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
760 ref
= InterlockedDecrement(&This
->ref
);
762 if (This
->key
) RegCloseKey(This
->key
);
763 HeapFree(GetProcessHeap(), 0, This
);
769 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Next(
770 IEnumCATEGORYINFO
*iface
,
775 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
780 if (rgelt
== NULL
) return E_POINTER
;
782 if (This
->key
) while (fetched
< celt
) {
785 WCHAR catid
[CHARS_IN_GUID
];
786 DWORD cName
= CHARS_IN_GUID
;
789 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
790 NULL
, NULL
, NULL
, NULL
);
791 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
792 ++(This
->next_index
);
794 hr
= CLSIDFromString(catid
, &rgelt
->catid
);
795 if (FAILED(hr
)) continue;
797 res
= open_classes_key(This
->key
, catid
, KEY_READ
, &subkey
);
798 if (res
!= ERROR_SUCCESS
) continue;
800 hr
= COMCAT_GetCategoryDesc(subkey
, This
->lcid
,
801 rgelt
->szDescription
, 128);
803 if (FAILED(hr
)) continue;
805 rgelt
->lcid
= This
->lcid
;
810 if (pceltFetched
) *pceltFetched
= fetched
;
811 return fetched
== celt
? S_OK
: S_FALSE
;
814 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Skip(
815 IEnumCATEGORYINFO
*iface
,
818 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
822 This
->next_index
+= celt
;
823 /* This should return S_FALSE when there aren't celt elems to skip. */
827 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Reset(IEnumCATEGORYINFO
*iface
)
829 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
833 This
->next_index
= 0;
837 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Clone(
838 IEnumCATEGORYINFO
*iface
,
839 IEnumCATEGORYINFO
**ppenum
)
841 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
842 IEnumCATEGORYINFOImpl
*new_this
;
846 if (ppenum
== NULL
) return E_POINTER
;
848 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
849 if (new_this
== NULL
) return E_OUTOFMEMORY
;
851 new_this
->IEnumCATEGORYINFO_iface
= This
->IEnumCATEGORYINFO_iface
;
853 new_this
->lcid
= This
->lcid
;
854 /* FIXME: could we more efficiently use DuplicateHandle? */
855 open_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
, &new_this
->key
);
856 new_this
->next_index
= This
->next_index
;
858 *ppenum
= &new_this
->IEnumCATEGORYINFO_iface
;
862 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl
=
864 COMCAT_IEnumCATEGORYINFO_QueryInterface
,
865 COMCAT_IEnumCATEGORYINFO_AddRef
,
866 COMCAT_IEnumCATEGORYINFO_Release
,
867 COMCAT_IEnumCATEGORYINFO_Next
,
868 COMCAT_IEnumCATEGORYINFO_Skip
,
869 COMCAT_IEnumCATEGORYINFO_Reset
,
870 COMCAT_IEnumCATEGORYINFO_Clone
873 static HRESULT
EnumCATEGORYINFO_Construct(LCID lcid
, IEnumCATEGORYINFO
**ret
)
875 IEnumCATEGORYINFOImpl
*This
;
879 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
880 if (!This
) return E_OUTOFMEMORY
;
882 This
->IEnumCATEGORYINFO_iface
.lpVtbl
= &COMCAT_IEnumCATEGORYINFO_Vtbl
;
885 open_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
, &This
->key
);
887 *ret
= &This
->IEnumCATEGORYINFO_iface
;
891 /**********************************************************************
892 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
894 * This implementation is not thread-safe. The manager itself is, but
895 * I can't imagine a valid use of an enumerator in several threads.
899 IEnumGUID IEnumGUID_iface
;
901 struct class_categories
*categories
;
904 } CLSID_IEnumGUIDImpl
;
906 static inline CLSID_IEnumGUIDImpl
*impl_from_IEnumCLSID(IEnumGUID
*iface
)
908 return CONTAINING_RECORD(iface
, CLSID_IEnumGUIDImpl
, IEnumGUID_iface
);
911 static HRESULT WINAPI
CLSIDEnumGUID_QueryInterface(
916 TRACE("%s\n",debugstr_guid(riid
));
918 if (ppvObj
== NULL
) return E_POINTER
;
920 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
921 IsEqualGUID(riid
, &IID_IEnumGUID
))
924 IEnumGUID_AddRef(iface
);
928 return E_NOINTERFACE
;
931 static ULONG WINAPI
CLSIDEnumGUID_AddRef(IEnumGUID
*iface
)
933 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
936 return InterlockedIncrement(&This
->ref
);
939 static ULONG WINAPI
CLSIDEnumGUID_Release(IEnumGUID
*iface
)
941 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
946 ref
= InterlockedDecrement(&This
->ref
);
948 if (This
->key
) RegCloseKey(This
->key
);
949 HeapFree(GetProcessHeap(), 0, This
->categories
);
950 HeapFree(GetProcessHeap(), 0, This
);
956 static HRESULT WINAPI
CLSIDEnumGUID_Next(
962 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
967 if (rgelt
== NULL
) return E_POINTER
;
969 if (This
->key
) while (fetched
< celt
) {
972 WCHAR clsid
[CHARS_IN_GUID
];
973 DWORD cName
= CHARS_IN_GUID
;
976 res
= RegEnumKeyExW(This
->key
, This
->next_index
, clsid
, &cName
,
977 NULL
, NULL
, NULL
, NULL
);
978 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
979 ++(This
->next_index
);
981 hr
= CLSIDFromString(clsid
, rgelt
);
982 if (FAILED(hr
)) continue;
984 res
= open_classes_key(This
->key
, clsid
, KEY_READ
, &subkey
);
985 if (res
!= ERROR_SUCCESS
) continue;
987 hr
= COMCAT_IsClassOfCategories(subkey
, This
->categories
);
989 if (hr
!= S_OK
) continue;
995 if (pceltFetched
) *pceltFetched
= fetched
;
996 return fetched
== celt
? S_OK
: S_FALSE
;
999 static HRESULT WINAPI
CLSIDEnumGUID_Skip(
1003 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1007 This
->next_index
+= celt
;
1008 FIXME("Never returns S_FALSE\n");
1012 static HRESULT WINAPI
CLSIDEnumGUID_Reset(IEnumGUID
*iface
)
1014 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1018 This
->next_index
= 0;
1022 static HRESULT WINAPI
CLSIDEnumGUID_Clone(
1026 CLSID_IEnumGUIDImpl
*This
= impl_from_IEnumCLSID(iface
);
1027 CLSID_IEnumGUIDImpl
*cloned
;
1029 TRACE("(%p)->(%p)\n", This
, ppenum
);
1031 if (ppenum
== NULL
) return E_POINTER
;
1035 cloned
= HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID_IEnumGUIDImpl
));
1036 if (cloned
== NULL
) return E_OUTOFMEMORY
;
1038 cloned
->IEnumGUID_iface
.lpVtbl
= This
->IEnumGUID_iface
.lpVtbl
;
1041 cloned
->categories
= HeapAlloc(GetProcessHeap(), 0, This
->categories
->size
);
1042 if (cloned
->categories
== NULL
) {
1043 HeapFree(GetProcessHeap(), 0, cloned
);
1044 return E_OUTOFMEMORY
;
1046 memcpy(cloned
->categories
, This
->categories
, This
->categories
->size
);
1049 open_classes_key(HKEY_CLASSES_ROOT
, L
"CLSID", KEY_READ
, &cloned
->key
);
1050 cloned
->next_index
= This
->next_index
;
1052 *ppenum
= &cloned
->IEnumGUID_iface
;
1056 static const IEnumGUIDVtbl CLSIDEnumGUIDVtbl
=
1058 CLSIDEnumGUID_QueryInterface
,
1059 CLSIDEnumGUID_AddRef
,
1060 CLSIDEnumGUID_Release
,
1063 CLSIDEnumGUID_Reset
,
1067 static HRESULT
CLSIDEnumGUID_Construct(struct class_categories
*categories
, IEnumCLSID
**ret
)
1069 CLSID_IEnumGUIDImpl
*This
;
1073 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLSID_IEnumGUIDImpl
));
1074 if (!This
) return E_OUTOFMEMORY
;
1076 This
->IEnumGUID_iface
.lpVtbl
= &CLSIDEnumGUIDVtbl
;
1078 This
->categories
= categories
;
1079 open_classes_key(HKEY_CLASSES_ROOT
, L
"CLSID", KEY_READ
, &This
->key
);
1081 *ret
= &This
->IEnumGUID_iface
;
1086 /**********************************************************************
1087 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1089 * This implementation is not thread-safe. The manager itself is, but
1090 * I can't imagine a valid use of an enumerator in several threads.
1094 IEnumGUID IEnumGUID_iface
;
1099 } CATID_IEnumGUIDImpl
;
1101 static inline CATID_IEnumGUIDImpl
*impl_from_IEnumCATID(IEnumGUID
*iface
)
1103 return CONTAINING_RECORD(iface
, CATID_IEnumGUIDImpl
, IEnumGUID_iface
);
1106 static HRESULT WINAPI
CATIDEnumGUID_QueryInterface(
1111 TRACE("%s\n",debugstr_guid(riid
));
1113 if (ppvObj
== NULL
) return E_POINTER
;
1115 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
1116 IsEqualGUID(riid
, &IID_IEnumGUID
))
1119 IEnumGUID_AddRef(iface
);
1123 return E_NOINTERFACE
;
1126 static ULONG WINAPI
CATIDEnumGUID_AddRef(IEnumGUID
*iface
)
1128 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1131 return InterlockedIncrement(&This
->ref
);
1134 static ULONG WINAPI
CATIDEnumGUID_Release(IEnumGUID
*iface
)
1136 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1141 ref
= InterlockedDecrement(&This
->ref
);
1143 if (This
->key
) RegCloseKey(This
->key
);
1144 HeapFree(GetProcessHeap(), 0, This
);
1150 static HRESULT WINAPI
CATIDEnumGUID_Next(
1154 ULONG
*pceltFetched
)
1156 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1161 if (rgelt
== NULL
) return E_POINTER
;
1163 if (This
->key
) while (fetched
< celt
) {
1166 WCHAR catid
[CHARS_IN_GUID
];
1167 DWORD cName
= CHARS_IN_GUID
;
1169 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
1170 NULL
, NULL
, NULL
, NULL
);
1171 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1172 ++(This
->next_index
);
1174 hr
= CLSIDFromString(catid
, rgelt
);
1175 if (FAILED(hr
)) continue;
1181 if (pceltFetched
) *pceltFetched
= fetched
;
1182 return fetched
== celt
? S_OK
: S_FALSE
;
1185 static HRESULT WINAPI
CATIDEnumGUID_Skip(
1189 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1193 This
->next_index
+= celt
;
1194 FIXME("Never returns S_FALSE\n");
1198 static HRESULT WINAPI
CATIDEnumGUID_Reset(IEnumGUID
*iface
)
1200 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1204 This
->next_index
= 0;
1208 static HRESULT WINAPI
CATIDEnumGUID_Clone(
1212 CATID_IEnumGUIDImpl
*This
= impl_from_IEnumCATID(iface
);
1213 CATID_IEnumGUIDImpl
*new_this
;
1217 if (ppenum
== NULL
) return E_POINTER
;
1219 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1220 if (new_this
== NULL
) return E_OUTOFMEMORY
;
1222 new_this
->IEnumGUID_iface
.lpVtbl
= This
->IEnumGUID_iface
.lpVtbl
;
1224 lstrcpyW(new_this
->keyname
, This
->keyname
);
1225 /* FIXME: could we more efficiently use DuplicateHandle? */
1226 open_classes_key(HKEY_CLASSES_ROOT
, new_this
->keyname
, KEY_READ
, &new_this
->key
);
1227 new_this
->next_index
= This
->next_index
;
1229 *ppenum
= &new_this
->IEnumGUID_iface
;
1233 static const IEnumGUIDVtbl CATIDEnumGUIDVtbl
=
1235 CATIDEnumGUID_QueryInterface
,
1236 CATIDEnumGUID_AddRef
,
1237 CATIDEnumGUID_Release
,
1240 CATIDEnumGUID_Reset
,
1244 static HRESULT
CATIDEnumGUID_Construct(REFCLSID rclsid
, LPCWSTR postfix
, IEnumGUID
**ret
)
1246 WCHAR keyname
[100], clsidW
[CHARS_IN_GUID
];
1247 CATID_IEnumGUIDImpl
*This
;
1251 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1252 if (!This
) return E_OUTOFMEMORY
;
1254 StringFromGUID2(rclsid
, clsidW
, CHARS_IN_GUID
);
1256 This
->IEnumGUID_iface
.lpVtbl
= &CATIDEnumGUIDVtbl
;
1258 lstrcpyW(keyname
, L
"CLSID\\");
1259 lstrcatW(keyname
, clsidW
);
1260 lstrcatW(keyname
, postfix
);
1262 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
1264 *ret
= &This
->IEnumGUID_iface
;