2 * Comcat implementation
4 * Copyright (C) 2002 John K. Hohm
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "compobj_private.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
41 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
;
42 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl
;
46 ICatRegister ICatRegister_iface
;
47 ICatInformation ICatInformation_iface
;
50 /* static ComCatMgr instance */
51 static ComCatMgrImpl COMCAT_ComCatMgr
=
53 { &COMCAT_ICatRegister_Vtbl
},
54 { &COMCAT_ICatInformation_Vtbl
}
57 struct class_categories
{
62 static IEnumCATEGORYINFO
*COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid
);
63 static LPENUMGUID
COMCAT_CLSID_IEnumGUID_Construct(struct class_categories
*class_categories
);
64 static LPENUMGUID
COMCAT_CATID_IEnumGUID_Construct(REFCLSID rclsid
, LPCWSTR impl_req
);
66 /**********************************************************************
67 * File-scope string constants
69 static const WCHAR comcat_keyname
[] = {
70 'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0 };
71 static const WCHAR impl_keyname
[] = {
72 'I','m','p','l','e','m','e','n','t','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
73 static const WCHAR req_keyname
[] = {
74 'R','e','q','u','i','r','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
75 static const WCHAR clsid_keyname
[] = { 'C','L','S','I','D',0 };
78 /**********************************************************************
79 * COMCAT_RegisterClassCategories
81 static HRESULT
COMCAT_RegisterClassCategories(
89 HKEY clsid_key
, class_key
, type_key
;
91 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
93 /* Format the class key name. */
94 res
= StringFromGUID2(rclsid
, keyname
, 39);
95 if (FAILED(res
)) return res
;
97 /* Create (or open) the CLSID key. */
98 res
= create_classes_key(HKEY_CLASSES_ROOT
, clsid_keyname
, KEY_READ
|KEY_WRITE
, &clsid_key
);
99 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
101 /* Create (or open) the class key. */
102 res
= create_classes_key(clsid_key
, keyname
, KEY_READ
|KEY_WRITE
, &class_key
);
103 if (res
== ERROR_SUCCESS
) {
104 /* Create (or open) the category type key. */
105 res
= create_classes_key(class_key
, type
, KEY_READ
|KEY_WRITE
, &type_key
);
106 if (res
== ERROR_SUCCESS
) {
107 for (; cCategories
; --cCategories
, ++rgcatid
) {
110 /* Format the category key name. */
111 res
= StringFromGUID2(rgcatid
, keyname
, 39);
112 if (FAILED(res
)) continue;
114 /* Do the register. */
115 res
= create_classes_key(type_key
, keyname
, KEY_READ
|KEY_WRITE
, &key
);
116 if (res
== ERROR_SUCCESS
) RegCloseKey(key
);
120 RegCloseKey(class_key
);
122 RegCloseKey(clsid_key
);
127 /**********************************************************************
128 * COMCAT_UnRegisterClassCategories
130 static HRESULT
COMCAT_UnRegisterClassCategories(
134 const CATID
*rgcatid
)
136 WCHAR keyname
[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
140 if (cCategories
&& rgcatid
== NULL
) return E_POINTER
;
142 /* Format the class category type key name. */
143 res
= StringFromGUID2(rclsid
, keyname
+ 6, 39);
144 if (FAILED(res
)) return res
;
146 lstrcpyW(keyname
+ 45, type
);
148 /* Open the class category type key. */
149 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
|KEY_WRITE
, &type_key
);
150 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
152 for (; cCategories
; --cCategories
, ++rgcatid
) {
153 /* Format the category key name. */
154 res
= StringFromGUID2(rgcatid
, keyname
, 39);
155 if (FAILED(res
)) continue;
157 /* Do the unregister. */
158 RegDeleteKeyW(type_key
, keyname
);
160 RegCloseKey(type_key
);
165 /**********************************************************************
166 * COMCAT_GetCategoryDesc
168 static HRESULT
COMCAT_GetCategoryDesc(HKEY key
, LCID lcid
, PWCHAR pszDesc
,
171 static const WCHAR fmt
[] = { '%', 'l', 'X', 0 };
174 DWORD type
, size
= (buf_wchars
- 1) * sizeof(WCHAR
);
176 if (pszDesc
== NULL
) return E_INVALIDARG
;
178 /* FIXME: lcid comparisons are more complex than this! */
179 wsprintfW(valname
, fmt
, lcid
);
180 res
= RegQueryValueExW(key
, valname
, 0, &type
, (LPBYTE
)pszDesc
, &size
);
181 if (res
!= ERROR_SUCCESS
|| type
!= REG_SZ
) {
182 FIXME("Simplified lcid comparison\n");
183 return CAT_E_NODESCRIPTION
;
185 pszDesc
[size
/ sizeof(WCHAR
)] = 0;
190 /**********************************************************************
191 * COMCAT_PrepareClassCategories
193 static struct class_categories
*COMCAT_PrepareClassCategories(
194 ULONG impl_count
, const CATID
*impl_catids
, ULONG req_count
, const CATID
*req_catids
)
196 struct class_categories
*categories
;
199 categories
= HeapAlloc(
200 GetProcessHeap(), HEAP_ZERO_MEMORY
,
201 sizeof(struct class_categories
) +
202 ((impl_count
+ req_count
) * 39 + 2) * sizeof(WCHAR
));
203 if (categories
== NULL
) return categories
;
205 strings
= (WCHAR
*)(categories
+ 1);
206 categories
->impl_strings
= strings
;
207 while (impl_count
--) {
208 StringFromGUID2(impl_catids
++, strings
, 39);
213 categories
->req_strings
= strings
;
214 while (req_count
--) {
215 StringFromGUID2(req_catids
++, strings
, 39);
223 /**********************************************************************
224 * COMCAT_IsClassOfCategories
226 static HRESULT
COMCAT_IsClassOfCategories(
228 struct class_categories
const* categories
)
235 /* Check that every given category is implemented by class. */
236 if (*categories
->impl_strings
) {
237 res
= open_classes_key(key
, impl_keyname
, KEY_READ
, &subkey
);
238 if (res
!= ERROR_SUCCESS
) return S_FALSE
;
239 for (string
= categories
->impl_strings
; *string
; string
+= 39) {
241 res
= open_classes_key(subkey
, string
, 0, &catkey
);
242 if (res
!= ERROR_SUCCESS
) {
251 /* Check that all categories required by class are given. */
252 res
= open_classes_key(key
, req_keyname
, KEY_READ
, &subkey
);
253 if (res
== ERROR_SUCCESS
) {
254 for (index
= 0; ; ++index
) {
258 res
= RegEnumKeyExW(subkey
, index
, keyname
, &size
,
259 NULL
, NULL
, NULL
, NULL
);
260 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
261 if (size
!= 38) continue; /* bogus catid in registry */
262 for (string
= categories
->req_strings
; *string
; string
+= 39)
263 if (!strcmpiW(string
, keyname
)) break;
275 /**********************************************************************
276 * COMCAT_ICatRegister_QueryInterface
278 static HRESULT WINAPI
COMCAT_ICatRegister_QueryInterface(
283 TRACE("%s\n",debugstr_guid(riid
));
285 if (ppvObj
== NULL
) return E_POINTER
;
287 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ICatRegister
)) {
289 ICatRegister_AddRef(iface
);
293 if (IsEqualGUID(riid
, &IID_ICatInformation
)) {
294 *ppvObj
= &COMCAT_ComCatMgr
.ICatInformation_iface
;
295 ICatRegister_AddRef(iface
);
299 return E_NOINTERFACE
;
302 /**********************************************************************
303 * COMCAT_ICatRegister_AddRef
305 static ULONG WINAPI
COMCAT_ICatRegister_AddRef(LPCATREGISTER iface
)
307 return 2; /* non-heap based object */
310 /**********************************************************************
311 * COMCAT_ICatRegister_Release
313 static ULONG WINAPI
COMCAT_ICatRegister_Release(LPCATREGISTER iface
)
315 return 1; /* non-heap based object */
318 /**********************************************************************
319 * COMCAT_ICatRegister_RegisterCategories
321 static HRESULT WINAPI
COMCAT_ICatRegister_RegisterCategories(
331 if (cCategories
&& rgci
== NULL
)
334 /* Create (or open) the component categories key. */
335 res
= create_classes_key(HKEY_CLASSES_ROOT
, comcat_keyname
, KEY_READ
|KEY_WRITE
, &comcat_key
);
336 if (res
!= ERROR_SUCCESS
) return E_FAIL
;
338 for (; cCategories
; --cCategories
, ++rgci
) {
339 static const WCHAR fmt
[] = { '%', 'l', 'X', 0 };
344 /* Create (or open) the key for this category. */
345 if (!StringFromGUID2(&rgci
->catid
, keyname
, 39)) continue;
346 res
= create_classes_key(comcat_key
, keyname
, KEY_READ
|KEY_WRITE
, &cat_key
);
347 if (res
!= ERROR_SUCCESS
) continue;
349 /* Set the value for this locale's description. */
350 wsprintfW(valname
, fmt
, rgci
->lcid
);
351 RegSetValueExW(cat_key
, valname
, 0, REG_SZ
, (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
) {
384 /* Delete the key for this category. */
385 if (!StringFromGUID2(rgcatid
, keyname
, 39)) 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 *ppenumCatInfo
= COMCAT_IEnumCATEGORYINFO_Construct(lcid
);
493 if (*ppenumCatInfo
== NULL
) return E_OUTOFMEMORY
;
494 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo
);
498 /**********************************************************************
499 * COMCAT_ICatInformation_GetCategoryDesc
501 static HRESULT WINAPI
COMCAT_ICatInformation_GetCategoryDesc(
502 LPCATINFORMATION iface
,
507 WCHAR keyname
[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
508 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
509 'r', 'i', 'e', 's', '\\', 0 };
513 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid
), lcid
);
515 if (rcatid
== NULL
|| ppszDesc
== NULL
) return E_INVALIDARG
;
517 /* Open the key for this category. */
518 if (!StringFromGUID2(rcatid
, keyname
+ 21, 39)) return E_FAIL
;
519 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &key
);
520 if (res
!= ERROR_SUCCESS
) return CAT_E_CATIDNOEXIST
;
522 /* Allocate a sensible amount of memory for the description. */
523 *ppszDesc
= CoTaskMemAlloc(128 * sizeof(WCHAR
));
524 if (*ppszDesc
== NULL
) {
526 return E_OUTOFMEMORY
;
529 /* Get the description, and make sure it's null terminated. */
530 res
= COMCAT_GetCategoryDesc(key
, lcid
, *ppszDesc
, 128);
533 CoTaskMemFree(*ppszDesc
);
540 /**********************************************************************
541 * COMCAT_ICatInformation_EnumClassesOfCategories
543 static HRESULT WINAPI
COMCAT_ICatInformation_EnumClassesOfCategories(
544 LPCATINFORMATION iface
,
549 LPENUMCLSID
*ppenumCLSID
)
551 struct class_categories
*categories
;
555 if (cImplemented
== (ULONG
)-1)
557 if (cRequired
== (ULONG
)-1)
560 if (ppenumCLSID
== NULL
||
561 (cImplemented
&& rgcatidImpl
== NULL
) ||
562 (cRequired
&& rgcatidReq
== NULL
)) return E_POINTER
;
564 categories
= COMCAT_PrepareClassCategories(cImplemented
, rgcatidImpl
,
565 cRequired
, rgcatidReq
);
566 if (categories
== NULL
) return E_OUTOFMEMORY
;
567 *ppenumCLSID
= COMCAT_CLSID_IEnumGUID_Construct(categories
);
568 if (*ppenumCLSID
== NULL
) {
569 HeapFree(GetProcessHeap(), 0, categories
);
570 return E_OUTOFMEMORY
;
572 IEnumGUID_AddRef(*ppenumCLSID
);
576 /**********************************************************************
577 * COMCAT_ICatInformation_IsClassOfCategories
579 static HRESULT WINAPI
COMCAT_ICatInformation_IsClassOfCategories(
580 LPCATINFORMATION iface
,
587 WCHAR keyname
[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
589 struct class_categories
*categories
;
594 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid
),cImplemented
);
595 for (count
= 0; count
< cImplemented
; ++count
)
596 TRACE(" %s\n",debugstr_guid(&rgcatidImpl
[count
]));
597 TRACE("Required %u\n",cRequired
);
598 for (count
= 0; count
< cRequired
; ++count
)
599 TRACE(" %s\n",debugstr_guid(&rgcatidReq
[count
]));
602 if ((cImplemented
&& rgcatidImpl
== NULL
) ||
603 (cRequired
&& rgcatidReq
== NULL
)) return E_POINTER
;
605 res
= StringFromGUID2(rclsid
, keyname
+ 6, 39);
606 if (FAILED(res
)) return res
;
608 categories
= COMCAT_PrepareClassCategories(cImplemented
, rgcatidImpl
,
609 cRequired
, rgcatidReq
);
610 if (categories
== NULL
) return E_OUTOFMEMORY
;
612 res
= open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &key
);
613 if (res
== ERROR_SUCCESS
) {
614 res
= COMCAT_IsClassOfCategories(key
, categories
);
616 } else res
= S_FALSE
;
618 HeapFree(GetProcessHeap(), 0, categories
);
623 /**********************************************************************
624 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
626 static HRESULT WINAPI
COMCAT_ICatInformation_EnumImplCategoriesOfClass(
627 LPCATINFORMATION iface
,
629 LPENUMCATID
*ppenumCATID
)
631 static const WCHAR postfix
[] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
632 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
633 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
635 TRACE("%s\n",debugstr_guid(rclsid
));
637 if (rclsid
== NULL
|| ppenumCATID
== NULL
)
640 *ppenumCATID
= COMCAT_CATID_IEnumGUID_Construct(rclsid
, postfix
);
641 if (*ppenumCATID
== NULL
) return E_OUTOFMEMORY
;
645 /**********************************************************************
646 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
648 static HRESULT WINAPI
COMCAT_ICatInformation_EnumReqCategoriesOfClass(
649 LPCATINFORMATION iface
,
651 LPENUMCATID
*ppenumCATID
)
653 static const WCHAR postfix
[] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
654 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
655 'r', 'i', 'e', 's', 0 };
657 TRACE("%s\n",debugstr_guid(rclsid
));
659 if (rclsid
== NULL
|| ppenumCATID
== NULL
)
662 *ppenumCATID
= COMCAT_CATID_IEnumGUID_Construct(rclsid
, postfix
);
663 if (*ppenumCATID
== NULL
) return E_OUTOFMEMORY
;
667 /**********************************************************************
668 * COMCAT_ICatRegister_Vtbl
670 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl
=
672 COMCAT_ICatRegister_QueryInterface
,
673 COMCAT_ICatRegister_AddRef
,
674 COMCAT_ICatRegister_Release
,
675 COMCAT_ICatRegister_RegisterCategories
,
676 COMCAT_ICatRegister_UnRegisterCategories
,
677 COMCAT_ICatRegister_RegisterClassImplCategories
,
678 COMCAT_ICatRegister_UnRegisterClassImplCategories
,
679 COMCAT_ICatRegister_RegisterClassReqCategories
,
680 COMCAT_ICatRegister_UnRegisterClassReqCategories
684 /**********************************************************************
685 * COMCAT_ICatInformation_Vtbl
687 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl
=
689 COMCAT_ICatInformation_QueryInterface
,
690 COMCAT_ICatInformation_AddRef
,
691 COMCAT_ICatInformation_Release
,
692 COMCAT_ICatInformation_EnumCategories
,
693 COMCAT_ICatInformation_GetCategoryDesc
,
694 COMCAT_ICatInformation_EnumClassesOfCategories
,
695 COMCAT_ICatInformation_IsClassOfCategories
,
696 COMCAT_ICatInformation_EnumImplCategoriesOfClass
,
697 COMCAT_ICatInformation_EnumReqCategoriesOfClass
700 /**********************************************************************
701 * COMCAT_IClassFactory_QueryInterface (also IUnknown)
703 static HRESULT WINAPI
COMCAT_IClassFactory_QueryInterface(
704 LPCLASSFACTORY iface
,
708 TRACE("%s\n",debugstr_guid(riid
));
710 if (ppvObj
== NULL
) return E_POINTER
;
712 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
713 IsEqualGUID(riid
, &IID_IClassFactory
))
716 IClassFactory_AddRef(iface
);
720 return E_NOINTERFACE
;
723 /**********************************************************************
724 * COMCAT_IClassFactory_AddRef (also IUnknown)
726 static ULONG WINAPI
COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface
)
728 return 2; /* non-heap based object */
731 /**********************************************************************
732 * COMCAT_IClassFactory_Release (also IUnknown)
734 static ULONG WINAPI
COMCAT_IClassFactory_Release(LPCLASSFACTORY iface
)
736 return 1; /* non-heap based object */
739 /**********************************************************************
740 * COMCAT_IClassFactory_CreateInstance
742 static HRESULT WINAPI
COMCAT_IClassFactory_CreateInstance(
743 LPCLASSFACTORY iface
,
749 TRACE("%s\n",debugstr_guid(riid
));
751 if (ppvObj
== NULL
) return E_POINTER
;
753 /* Don't support aggregation (Windows doesn't) */
754 if (pUnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
756 res
= ICatRegister_QueryInterface(&COMCAT_ComCatMgr
.ICatRegister_iface
, riid
, ppvObj
);
757 if (SUCCEEDED(res
)) {
761 return CLASS_E_CLASSNOTAVAILABLE
;
764 /**********************************************************************
765 * COMCAT_IClassFactory_LockServer
767 static HRESULT WINAPI
COMCAT_IClassFactory_LockServer(
768 LPCLASSFACTORY iface
,
771 FIXME("(%d), stub!\n",fLock
);
775 /**********************************************************************
776 * static ClassFactory instance
778 static const IClassFactoryVtbl ComCatCFVtbl
=
780 COMCAT_IClassFactory_QueryInterface
,
781 COMCAT_IClassFactory_AddRef
,
782 COMCAT_IClassFactory_Release
,
783 COMCAT_IClassFactory_CreateInstance
,
784 COMCAT_IClassFactory_LockServer
787 static const IClassFactoryVtbl
*ComCatCF
= &ComCatCFVtbl
;
789 HRESULT
ComCatCF_Create(REFIID riid
, LPVOID
*ppv
)
791 return IClassFactory_QueryInterface((IClassFactory
*)&ComCatCF
, riid
, ppv
);
794 /**********************************************************************
795 * IEnumCATEGORYINFO implementation
797 * This implementation is not thread-safe. The manager itself is, but
798 * I can't imagine a valid use of an enumerator in several threads.
802 IEnumCATEGORYINFO IEnumCATEGORYINFO_iface
;
807 } IEnumCATEGORYINFOImpl
;
809 static inline IEnumCATEGORYINFOImpl
*impl_from_IEnumCATEGORYINFO(IEnumCATEGORYINFO
*iface
)
811 return CONTAINING_RECORD(iface
, IEnumCATEGORYINFOImpl
, IEnumCATEGORYINFO_iface
);
814 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_AddRef(IEnumCATEGORYINFO
*iface
)
816 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
820 return InterlockedIncrement(&This
->ref
);
823 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_QueryInterface(
824 IEnumCATEGORYINFO
*iface
,
828 TRACE("%s\n",debugstr_guid(riid
));
830 if (ppvObj
== NULL
) return E_POINTER
;
832 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
833 IsEqualGUID(riid
, &IID_IEnumCATEGORYINFO
))
836 COMCAT_IEnumCATEGORYINFO_AddRef(iface
);
840 return E_NOINTERFACE
;
843 static ULONG WINAPI
COMCAT_IEnumCATEGORYINFO_Release(IEnumCATEGORYINFO
*iface
)
845 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
850 ref
= InterlockedDecrement(&This
->ref
);
852 if (This
->key
) RegCloseKey(This
->key
);
853 HeapFree(GetProcessHeap(), 0, This
);
859 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Next(
860 IEnumCATEGORYINFO
*iface
,
865 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
870 if (rgelt
== NULL
) return E_POINTER
;
872 if (This
->key
) while (fetched
< celt
) {
879 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
880 NULL
, NULL
, NULL
, NULL
);
881 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
882 ++(This
->next_index
);
884 hr
= CLSIDFromString(catid
, &rgelt
->catid
);
885 if (FAILED(hr
)) continue;
887 res
= open_classes_key(This
->key
, catid
, KEY_READ
, &subkey
);
888 if (res
!= ERROR_SUCCESS
) continue;
890 hr
= COMCAT_GetCategoryDesc(subkey
, This
->lcid
,
891 rgelt
->szDescription
, 128);
893 if (FAILED(hr
)) continue;
895 rgelt
->lcid
= This
->lcid
;
900 if (pceltFetched
) *pceltFetched
= fetched
;
901 return fetched
== celt
? S_OK
: S_FALSE
;
904 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Skip(
905 IEnumCATEGORYINFO
*iface
,
908 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
912 This
->next_index
+= celt
;
913 /* This should return S_FALSE when there aren't celt elems to skip. */
917 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Reset(IEnumCATEGORYINFO
*iface
)
919 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
923 This
->next_index
= 0;
927 static HRESULT WINAPI
COMCAT_IEnumCATEGORYINFO_Clone(
928 IEnumCATEGORYINFO
*iface
,
929 IEnumCATEGORYINFO
**ppenum
)
931 IEnumCATEGORYINFOImpl
*This
= impl_from_IEnumCATEGORYINFO(iface
);
932 static const WCHAR keyname
[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
933 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
934 'r', 'i', 'e', 's', 0 };
935 IEnumCATEGORYINFOImpl
*new_this
;
939 if (ppenum
== NULL
) return E_POINTER
;
941 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
942 if (new_this
== NULL
) return E_OUTOFMEMORY
;
944 new_this
->IEnumCATEGORYINFO_iface
= This
->IEnumCATEGORYINFO_iface
;
946 new_this
->lcid
= This
->lcid
;
947 /* FIXME: could we more efficiently use DuplicateHandle? */
948 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &new_this
->key
);
949 new_this
->next_index
= This
->next_index
;
951 *ppenum
= &new_this
->IEnumCATEGORYINFO_iface
;
955 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl
=
957 COMCAT_IEnumCATEGORYINFO_QueryInterface
,
958 COMCAT_IEnumCATEGORYINFO_AddRef
,
959 COMCAT_IEnumCATEGORYINFO_Release
,
960 COMCAT_IEnumCATEGORYINFO_Next
,
961 COMCAT_IEnumCATEGORYINFO_Skip
,
962 COMCAT_IEnumCATEGORYINFO_Reset
,
963 COMCAT_IEnumCATEGORYINFO_Clone
966 static IEnumCATEGORYINFO
*COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid
)
968 IEnumCATEGORYINFOImpl
*This
;
970 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IEnumCATEGORYINFOImpl
));
972 static const WCHAR keyname
[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
973 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
974 'r', 'i', 'e', 's', 0 };
976 This
->IEnumCATEGORYINFO_iface
.lpVtbl
= &COMCAT_IEnumCATEGORYINFO_Vtbl
;
978 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
980 return &This
->IEnumCATEGORYINFO_iface
;
983 /**********************************************************************
984 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
986 * This implementation is not thread-safe. The manager itself is, but
987 * I can't imagine a valid use of an enumerator in several threads.
991 const IEnumGUIDVtbl
*lpVtbl
;
993 struct class_categories
*categories
;
996 } CLSID_IEnumGUIDImpl
;
998 static ULONG WINAPI
COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface
)
1000 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1003 return InterlockedIncrement(&This
->ref
);
1006 static HRESULT WINAPI
COMCAT_CLSID_IEnumGUID_QueryInterface(
1011 TRACE("%s\n",debugstr_guid(riid
));
1013 if (ppvObj
== NULL
) return E_POINTER
;
1015 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
1016 IsEqualGUID(riid
, &IID_IEnumGUID
))
1019 COMCAT_CLSID_IEnumGUID_AddRef(iface
);
1023 return E_NOINTERFACE
;
1026 static ULONG WINAPI
COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface
)
1028 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1033 ref
= InterlockedDecrement(&This
->ref
);
1035 if (This
->key
) RegCloseKey(This
->key
);
1036 HeapFree(GetProcessHeap(), 0, This
->categories
);
1037 HeapFree(GetProcessHeap(), 0, This
);
1043 static HRESULT WINAPI
COMCAT_CLSID_IEnumGUID_Next(
1047 ULONG
*pceltFetched
)
1049 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1054 if (rgelt
== NULL
) return E_POINTER
;
1056 if (This
->key
) while (fetched
< celt
) {
1063 res
= RegEnumKeyExW(This
->key
, This
->next_index
, clsid
, &cName
,
1064 NULL
, NULL
, NULL
, NULL
);
1065 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1066 ++(This
->next_index
);
1068 hr
= CLSIDFromString(clsid
, rgelt
);
1069 if (FAILED(hr
)) continue;
1071 res
= open_classes_key(This
->key
, clsid
, KEY_READ
, &subkey
);
1072 if (res
!= ERROR_SUCCESS
) continue;
1074 hr
= COMCAT_IsClassOfCategories(subkey
, This
->categories
);
1075 RegCloseKey(subkey
);
1076 if (hr
!= S_OK
) continue;
1082 if (pceltFetched
) *pceltFetched
= fetched
;
1083 return fetched
== celt
? S_OK
: S_FALSE
;
1086 static HRESULT WINAPI
COMCAT_CLSID_IEnumGUID_Skip(
1090 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1094 This
->next_index
+= celt
;
1095 FIXME("Never returns S_FALSE\n");
1099 static HRESULT WINAPI
COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface
)
1101 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1105 This
->next_index
= 0;
1109 static HRESULT WINAPI
COMCAT_CLSID_IEnumGUID_Clone(
1113 CLSID_IEnumGUIDImpl
*This
= (CLSID_IEnumGUIDImpl
*)iface
;
1114 static const WCHAR keyname
[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1115 CLSID_IEnumGUIDImpl
*new_this
;
1120 if (ppenum
== NULL
) return E_POINTER
;
1122 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLSID_IEnumGUIDImpl
));
1123 if (new_this
== NULL
) return E_OUTOFMEMORY
;
1125 new_this
->lpVtbl
= This
->lpVtbl
;
1127 size
= HeapSize(GetProcessHeap(), 0, This
->categories
);
1128 new_this
->categories
=
1129 HeapAlloc(GetProcessHeap(), 0, size
);
1130 if (new_this
->categories
== NULL
) {
1131 HeapFree(GetProcessHeap(), 0, new_this
);
1132 return E_OUTOFMEMORY
;
1134 memcpy(new_this
->categories
, This
->categories
, size
);
1135 /* FIXME: could we more efficiently use DuplicateHandle? */
1136 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &new_this
->key
);
1137 new_this
->next_index
= This
->next_index
;
1139 *ppenum
= (LPENUMGUID
)new_this
;
1143 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl
=
1145 COMCAT_CLSID_IEnumGUID_QueryInterface
,
1146 COMCAT_CLSID_IEnumGUID_AddRef
,
1147 COMCAT_CLSID_IEnumGUID_Release
,
1148 COMCAT_CLSID_IEnumGUID_Next
,
1149 COMCAT_CLSID_IEnumGUID_Skip
,
1150 COMCAT_CLSID_IEnumGUID_Reset
,
1151 COMCAT_CLSID_IEnumGUID_Clone
1154 static LPENUMGUID
COMCAT_CLSID_IEnumGUID_Construct(struct class_categories
*categories
)
1156 CLSID_IEnumGUIDImpl
*This
;
1158 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLSID_IEnumGUIDImpl
));
1160 static const WCHAR keyname
[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1162 This
->lpVtbl
= &COMCAT_CLSID_IEnumGUID_Vtbl
;
1163 This
->categories
= categories
;
1164 open_classes_key(HKEY_CLASSES_ROOT
, keyname
, KEY_READ
, &This
->key
);
1166 return (LPENUMGUID
)This
;
1169 /**********************************************************************
1170 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1172 * This implementation is not thread-safe. The manager itself is, but
1173 * I can't imagine a valid use of an enumerator in several threads.
1177 const IEnumGUIDVtbl
*lpVtbl
;
1182 } CATID_IEnumGUIDImpl
;
1184 static ULONG WINAPI
COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface
)
1186 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1189 return InterlockedIncrement(&This
->ref
);
1192 static HRESULT WINAPI
COMCAT_CATID_IEnumGUID_QueryInterface(
1197 TRACE("%s\n",debugstr_guid(riid
));
1199 if (ppvObj
== NULL
) return E_POINTER
;
1201 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
1202 IsEqualGUID(riid
, &IID_IEnumGUID
))
1205 COMCAT_CATID_IEnumGUID_AddRef(iface
);
1209 return E_NOINTERFACE
;
1212 static ULONG WINAPI
COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface
)
1214 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1219 ref
= InterlockedDecrement(&This
->ref
);
1221 if (This
->key
) RegCloseKey(This
->key
);
1222 HeapFree(GetProcessHeap(), 0, This
);
1228 static HRESULT WINAPI
COMCAT_CATID_IEnumGUID_Next(
1232 ULONG
*pceltFetched
)
1234 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1239 if (rgelt
== NULL
) return E_POINTER
;
1241 if (This
->key
) while (fetched
< celt
) {
1247 res
= RegEnumKeyExW(This
->key
, This
->next_index
, catid
, &cName
,
1248 NULL
, NULL
, NULL
, NULL
);
1249 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) break;
1250 ++(This
->next_index
);
1252 hr
= CLSIDFromString(catid
, rgelt
);
1253 if (FAILED(hr
)) continue;
1259 if (pceltFetched
) *pceltFetched
= fetched
;
1260 return fetched
== celt
? S_OK
: S_FALSE
;
1263 static HRESULT WINAPI
COMCAT_CATID_IEnumGUID_Skip(
1267 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1271 This
->next_index
+= celt
;
1272 FIXME("Never returns S_FALSE\n");
1276 static HRESULT WINAPI
COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface
)
1278 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1282 This
->next_index
= 0;
1286 static HRESULT WINAPI
COMCAT_CATID_IEnumGUID_Clone(
1290 CATID_IEnumGUIDImpl
*This
= (CATID_IEnumGUIDImpl
*)iface
;
1291 CATID_IEnumGUIDImpl
*new_this
;
1295 if (ppenum
== NULL
) return E_POINTER
;
1297 new_this
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1298 if (new_this
== NULL
) return E_OUTOFMEMORY
;
1300 new_this
->lpVtbl
= This
->lpVtbl
;
1302 lstrcpyW(new_this
->keyname
, This
->keyname
);
1303 /* FIXME: could we more efficiently use DuplicateHandle? */
1304 open_classes_key(HKEY_CLASSES_ROOT
, new_this
->keyname
, KEY_READ
, &new_this
->key
);
1305 new_this
->next_index
= This
->next_index
;
1307 *ppenum
= (LPENUMGUID
)new_this
;
1311 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl
=
1313 COMCAT_CATID_IEnumGUID_QueryInterface
,
1314 COMCAT_CATID_IEnumGUID_AddRef
,
1315 COMCAT_CATID_IEnumGUID_Release
,
1316 COMCAT_CATID_IEnumGUID_Next
,
1317 COMCAT_CATID_IEnumGUID_Skip
,
1318 COMCAT_CATID_IEnumGUID_Reset
,
1319 COMCAT_CATID_IEnumGUID_Clone
1322 static LPENUMGUID
COMCAT_CATID_IEnumGUID_Construct(
1323 REFCLSID rclsid
, LPCWSTR postfix
)
1325 CATID_IEnumGUIDImpl
*This
;
1327 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CATID_IEnumGUIDImpl
));
1329 WCHAR prefix
[] = { 'C', 'L', 'S', 'I', 'D', '\\' };
1331 This
->lpVtbl
= &COMCAT_CATID_IEnumGUID_Vtbl
;
1332 memcpy(This
->keyname
, prefix
, sizeof(prefix
));
1333 StringFromGUID2(rclsid
, This
->keyname
+ 6, 39);
1334 lstrcpyW(This
->keyname
+ 44, postfix
);
1335 open_classes_key(HKEY_CLASSES_ROOT
, This
->keyname
, KEY_READ
, &This
->key
);
1337 return (LPENUMGUID
)This
;