gdi32: Pass the source/dest visible rectangles to the AlphaBlend driver entry point.
[wine/testsucceed.git] / dlls / ole32 / comcat.c
blob20151aee44ba8b13a7791b5bd5749ed20c33ce65
1 /*
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
21 #include <string.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "ole2.h"
33 #include "comcat.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ole);
39 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl;
40 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl;
42 typedef struct
44 ICatRegister ICatRegister_iface;
45 ICatInformation ICatInformation_iface;
46 } ComCatMgrImpl;
48 /* static ComCatMgr instance */
49 static ComCatMgrImpl COMCAT_ComCatMgr =
51 { &COMCAT_ICatRegister_Vtbl },
52 { &COMCAT_ICatInformation_Vtbl }
55 struct class_categories {
56 LPCWSTR impl_strings;
57 LPCWSTR req_strings;
60 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid);
61 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *class_categories);
62 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(REFCLSID rclsid, LPCWSTR impl_req);
64 /**********************************************************************
65 * File-scope string constants
67 static const WCHAR comcat_keyname[] = {
68 'C','o','m','p','o','n','e','n','t',' ','C','a','t','e','g','o','r','i','e','s',0 };
69 static const WCHAR impl_keyname[] = {
70 'I','m','p','l','e','m','e','n','t','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
71 static const WCHAR req_keyname[] = {
72 'R','e','q','u','i','r','e','d',' ','C','a','t','e','g','o','r','i','e','s',0 };
73 static const WCHAR clsid_keyname[] = { 'C','L','S','I','D',0 };
76 /**********************************************************************
77 * COMCAT_RegisterClassCategories
79 static HRESULT COMCAT_RegisterClassCategories(
80 REFCLSID rclsid,
81 LPCWSTR type,
82 ULONG cCategories,
83 const CATID *rgcatid)
85 WCHAR keyname[39];
86 HRESULT res;
87 HKEY clsid_key, class_key, type_key;
89 if (cCategories && rgcatid == NULL) return E_POINTER;
91 /* Format the class key name. */
92 res = StringFromGUID2(rclsid, keyname, 39);
93 if (FAILED(res)) return res;
95 /* Create (or open) the CLSID key. */
96 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
97 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
98 if (res != ERROR_SUCCESS) return E_FAIL;
100 /* Create (or open) the class key. */
101 res = RegCreateKeyExW(clsid_key, keyname, 0, NULL, 0,
102 KEY_READ | KEY_WRITE, NULL, &class_key, NULL);
103 if (res == ERROR_SUCCESS) {
104 /* Create (or open) the category type key. */
105 res = RegCreateKeyExW(class_key, type, 0, NULL, 0,
106 KEY_READ | KEY_WRITE, NULL, &type_key, NULL);
107 if (res == ERROR_SUCCESS) {
108 for (; cCategories; --cCategories, ++rgcatid) {
109 HKEY key;
111 /* Format the category key name. */
112 res = StringFromGUID2(rgcatid, keyname, 39);
113 if (FAILED(res)) continue;
115 /* Do the register. */
116 res = RegCreateKeyExW(type_key, keyname, 0, NULL, 0,
117 KEY_READ | KEY_WRITE, NULL, &key, NULL);
118 if (res == ERROR_SUCCESS) RegCloseKey(key);
120 res = S_OK;
121 } else res = E_FAIL;
122 RegCloseKey(class_key);
123 } else res = E_FAIL;
124 RegCloseKey(clsid_key);
126 return res;
129 /**********************************************************************
130 * COMCAT_UnRegisterClassCategories
132 static HRESULT COMCAT_UnRegisterClassCategories(
133 REFCLSID rclsid,
134 LPCWSTR type,
135 ULONG cCategories,
136 const CATID *rgcatid)
138 WCHAR keyname[68] = { 'C', 'L', 'S', 'I', 'D', '\\' };
139 HRESULT res;
140 HKEY type_key;
142 if (cCategories && rgcatid == NULL) return E_POINTER;
144 /* Format the class category type key name. */
145 res = StringFromGUID2(rclsid, keyname + 6, 39);
146 if (FAILED(res)) return res;
147 keyname[44] = '\\';
148 lstrcpyW(keyname + 45, type);
150 /* Open the class category type key. */
151 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0,
152 KEY_READ | KEY_WRITE, &type_key);
153 if (res != ERROR_SUCCESS) return E_FAIL;
155 for (; cCategories; --cCategories, ++rgcatid) {
156 /* Format the category key name. */
157 res = StringFromGUID2(rgcatid, keyname, 39);
158 if (FAILED(res)) continue;
160 /* Do the unregister. */
161 RegDeleteKeyW(type_key, keyname);
163 RegCloseKey(type_key);
165 return S_OK;
168 /**********************************************************************
169 * COMCAT_GetCategoryDesc
171 static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
172 ULONG buf_wchars)
174 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
175 WCHAR valname[5];
176 HRESULT res;
177 DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);
179 if (pszDesc == NULL) return E_INVALIDARG;
181 /* FIXME: lcid comparisons are more complex than this! */
182 wsprintfW(valname, fmt, lcid);
183 res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
184 if (res != ERROR_SUCCESS || type != REG_SZ) {
185 FIXME("Simplified lcid comparison\n");
186 return CAT_E_NODESCRIPTION;
188 pszDesc[size / sizeof(WCHAR)] = 0;
190 return S_OK;
193 /**********************************************************************
194 * COMCAT_PrepareClassCategories
196 static struct class_categories *COMCAT_PrepareClassCategories(
197 ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids)
199 struct class_categories *categories;
200 WCHAR *strings;
202 categories = HeapAlloc(
203 GetProcessHeap(), HEAP_ZERO_MEMORY,
204 sizeof(struct class_categories) +
205 ((impl_count + req_count) * 39 + 2) * sizeof(WCHAR));
206 if (categories == NULL) return categories;
208 strings = (WCHAR *)(categories + 1);
209 categories->impl_strings = strings;
210 while (impl_count--) {
211 StringFromGUID2(impl_catids++, strings, 39);
212 strings += 39;
214 *strings++ = 0;
216 categories->req_strings = strings;
217 while (req_count--) {
218 StringFromGUID2(req_catids++, strings, 39);
219 strings += 39;
221 *strings++ = 0;
223 return categories;
226 /**********************************************************************
227 * COMCAT_IsClassOfCategories
229 static HRESULT COMCAT_IsClassOfCategories(
230 HKEY key,
231 struct class_categories const* categories)
233 HKEY subkey;
234 HRESULT res;
235 DWORD index;
236 LPCWSTR string;
238 /* Check that every given category is implemented by class. */
239 if (*categories->impl_strings) {
240 res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
241 if (res != ERROR_SUCCESS) return S_FALSE;
242 for (string = categories->impl_strings; *string; string += 39) {
243 HKEY catkey;
244 res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
245 if (res != ERROR_SUCCESS) {
246 RegCloseKey(subkey);
247 return S_FALSE;
249 RegCloseKey(catkey);
251 RegCloseKey(subkey);
254 /* Check that all categories required by class are given. */
255 res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
256 if (res == ERROR_SUCCESS) {
257 for (index = 0; ; ++index) {
258 WCHAR keyname[39];
259 DWORD size = 39;
261 res = RegEnumKeyExW(subkey, index, keyname, &size,
262 NULL, NULL, NULL, NULL);
263 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
264 if (size != 38) continue; /* bogus catid in registry */
265 for (string = categories->req_strings; *string; string += 39)
266 if (!strcmpiW(string, keyname)) break;
267 if (!*string) {
268 RegCloseKey(subkey);
269 return S_FALSE;
272 RegCloseKey(subkey);
275 return S_OK;
278 /**********************************************************************
279 * COMCAT_ICatRegister_QueryInterface
281 static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
282 LPCATREGISTER iface,
283 REFIID riid,
284 LPVOID *ppvObj)
286 TRACE("%s\n",debugstr_guid(riid));
288 if (ppvObj == NULL) return E_POINTER;
290 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ICatRegister)) {
291 *ppvObj = iface;
292 ICatRegister_AddRef(iface);
293 return S_OK;
296 if (IsEqualGUID(riid, &IID_ICatInformation)) {
297 *ppvObj = &COMCAT_ComCatMgr.ICatInformation_iface;
298 ICatRegister_AddRef(iface);
299 return S_OK;
302 return E_NOINTERFACE;
305 /**********************************************************************
306 * COMCAT_ICatRegister_AddRef
308 static ULONG WINAPI COMCAT_ICatRegister_AddRef(LPCATREGISTER iface)
310 return 2; /* non-heap based object */
313 /**********************************************************************
314 * COMCAT_ICatRegister_Release
316 static ULONG WINAPI COMCAT_ICatRegister_Release(LPCATREGISTER iface)
318 return 1; /* non-heap based object */
321 /**********************************************************************
322 * COMCAT_ICatRegister_RegisterCategories
324 static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
325 LPCATREGISTER iface,
326 ULONG cCategories,
327 CATEGORYINFO *rgci)
329 HKEY comcat_key;
330 HRESULT res;
332 TRACE("\n");
334 if (cCategories && rgci == NULL)
335 return E_POINTER;
337 /* Create (or open) the component categories key. */
338 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
339 KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
340 if (res != ERROR_SUCCESS) return E_FAIL;
342 for (; cCategories; --cCategories, ++rgci) {
343 static const WCHAR fmt[] = { '%', 'l', 'X', 0 };
344 WCHAR keyname[39];
345 WCHAR valname[9];
346 HKEY cat_key;
348 /* Create (or open) the key for this category. */
349 if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
350 res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
351 KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
352 if (res != ERROR_SUCCESS) continue;
354 /* Set the value for this locale's description. */
355 wsprintfW(valname, fmt, rgci->lcid);
356 RegSetValueExW(cat_key, valname, 0, REG_SZ,
357 (CONST BYTE*)(rgci->szDescription),
358 (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR));
360 RegCloseKey(cat_key);
363 RegCloseKey(comcat_key);
364 return S_OK;
367 /**********************************************************************
368 * COMCAT_ICatRegister_UnRegisterCategories
370 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
371 LPCATREGISTER iface,
372 ULONG cCategories,
373 CATID *rgcatid)
375 HKEY comcat_key;
376 HRESULT res;
378 TRACE("\n");
380 if (cCategories && rgcatid == NULL)
381 return E_POINTER;
383 /* Open the component categories key. */
384 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
385 KEY_READ | KEY_WRITE, &comcat_key);
386 if (res != ERROR_SUCCESS) return E_FAIL;
388 for (; cCategories; --cCategories, ++rgcatid) {
389 WCHAR keyname[39];
391 /* Delete the key for this category. */
392 if (!StringFromGUID2(rgcatid, keyname, 39)) continue;
393 RegDeleteKeyW(comcat_key, keyname);
396 RegCloseKey(comcat_key);
397 return S_OK;
400 /**********************************************************************
401 * COMCAT_ICatRegister_RegisterClassImplCategories
403 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
404 LPCATREGISTER iface,
405 REFCLSID rclsid,
406 ULONG cCategories,
407 CATID *rgcatid)
409 TRACE("\n");
411 return COMCAT_RegisterClassCategories(
412 rclsid, impl_keyname, cCategories, rgcatid);
415 /**********************************************************************
416 * COMCAT_ICatRegister_UnRegisterClassImplCategories
418 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
419 LPCATREGISTER iface,
420 REFCLSID rclsid,
421 ULONG cCategories,
422 CATID *rgcatid)
424 TRACE("\n");
426 return COMCAT_UnRegisterClassCategories(
427 rclsid, impl_keyname, cCategories, rgcatid);
430 /**********************************************************************
431 * COMCAT_ICatRegister_RegisterClassReqCategories
433 static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
434 LPCATREGISTER iface,
435 REFCLSID rclsid,
436 ULONG cCategories,
437 CATID *rgcatid)
439 TRACE("\n");
441 return COMCAT_RegisterClassCategories(
442 rclsid, req_keyname, cCategories, rgcatid);
445 /**********************************************************************
446 * COMCAT_ICatRegister_UnRegisterClassReqCategories
448 static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
449 LPCATREGISTER iface,
450 REFCLSID rclsid,
451 ULONG cCategories,
452 CATID *rgcatid)
454 TRACE("\n");
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,
465 REFIID riid,
466 LPVOID *ppvObj)
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,
492 LCID lcid,
493 LPENUMCATEGORYINFO *ppenumCatInfo)
495 TRACE("\n");
497 if (ppenumCatInfo == NULL) return E_POINTER;
499 *ppenumCatInfo = COMCAT_IEnumCATEGORYINFO_Construct(lcid);
500 if (*ppenumCatInfo == NULL) return E_OUTOFMEMORY;
501 IEnumCATEGORYINFO_AddRef(*ppenumCatInfo);
502 return S_OK;
505 /**********************************************************************
506 * COMCAT_ICatInformation_GetCategoryDesc
508 static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
509 LPCATINFORMATION iface,
510 REFCATID rcatid,
511 LCID lcid,
512 PWCHAR *ppszDesc)
514 WCHAR keyname[60] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
515 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
516 'r', 'i', 'e', 's', '\\', 0 };
517 HKEY key;
518 HRESULT res;
520 TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid), lcid);
522 if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;
524 /* Open the key for this category. */
525 if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
526 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
527 if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
529 /* Allocate a sensible amount of memory for the description. */
530 *ppszDesc = CoTaskMemAlloc(128 * sizeof(WCHAR));
531 if (*ppszDesc == NULL) {
532 RegCloseKey(key);
533 return E_OUTOFMEMORY;
536 /* Get the description, and make sure it's null terminated. */
537 res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
538 RegCloseKey(key);
539 if (FAILED(res)) {
540 CoTaskMemFree(*ppszDesc);
541 return res;
544 return S_OK;
547 /**********************************************************************
548 * COMCAT_ICatInformation_EnumClassesOfCategories
550 static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
551 LPCATINFORMATION iface,
552 ULONG cImplemented,
553 CATID *rgcatidImpl,
554 ULONG cRequired,
555 CATID *rgcatidReq,
556 LPENUMCLSID *ppenumCLSID)
558 struct class_categories *categories;
560 TRACE("\n");
562 if (cImplemented == (ULONG)-1)
563 cImplemented = 0;
564 if (cRequired == (ULONG)-1)
565 cRequired = 0;
567 if (ppenumCLSID == NULL ||
568 (cImplemented && rgcatidImpl == NULL) ||
569 (cRequired && rgcatidReq == NULL)) return E_POINTER;
571 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
572 cRequired, rgcatidReq);
573 if (categories == NULL) return E_OUTOFMEMORY;
574 *ppenumCLSID = COMCAT_CLSID_IEnumGUID_Construct(categories);
575 if (*ppenumCLSID == NULL) {
576 HeapFree(GetProcessHeap(), 0, categories);
577 return E_OUTOFMEMORY;
579 IEnumGUID_AddRef(*ppenumCLSID);
580 return S_OK;
583 /**********************************************************************
584 * COMCAT_ICatInformation_IsClassOfCategories
586 static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
587 LPCATINFORMATION iface,
588 REFCLSID rclsid,
589 ULONG cImplemented,
590 CATID *rgcatidImpl,
591 ULONG cRequired,
592 CATID *rgcatidReq)
594 WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
595 HRESULT res;
596 struct class_categories *categories;
597 HKEY key;
599 if (WINE_TRACE_ON(ole)) {
600 ULONG count;
601 TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented);
602 for (count = 0; count < cImplemented; ++count)
603 TRACE(" %s\n",debugstr_guid(&rgcatidImpl[count]));
604 TRACE("Required %u\n",cRequired);
605 for (count = 0; count < cRequired; ++count)
606 TRACE(" %s\n",debugstr_guid(&rgcatidReq[count]));
609 if ((cImplemented && rgcatidImpl == NULL) ||
610 (cRequired && rgcatidReq == NULL)) return E_POINTER;
612 res = StringFromGUID2(rclsid, keyname + 6, 39);
613 if (FAILED(res)) return res;
615 categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
616 cRequired, rgcatidReq);
617 if (categories == NULL) return E_OUTOFMEMORY;
619 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
620 if (res == ERROR_SUCCESS) {
621 res = COMCAT_IsClassOfCategories(key, categories);
622 RegCloseKey(key);
623 } else res = S_FALSE;
625 HeapFree(GetProcessHeap(), 0, categories);
627 return res;
630 /**********************************************************************
631 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
633 static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
634 LPCATINFORMATION iface,
635 REFCLSID rclsid,
636 LPENUMCATID *ppenumCATID)
638 static const WCHAR postfix[24] = { '\\', 'I', 'm', 'p', 'l', 'e', 'm', 'e',
639 'n', 't', 'e', 'd', ' ', 'C', 'a', 't',
640 'e', 'g', 'o', 'r', 'i', 'e', 's', 0 };
642 TRACE("%s\n",debugstr_guid(rclsid));
644 if (rclsid == NULL || ppenumCATID == NULL)
645 return E_POINTER;
647 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
648 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
649 return S_OK;
652 /**********************************************************************
653 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
655 static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
656 LPCATINFORMATION iface,
657 REFCLSID rclsid,
658 LPENUMCATID *ppenumCATID)
660 static const WCHAR postfix[21] = { '\\', 'R', 'e', 'q', 'u', 'i', 'r', 'e',
661 'd', ' ', 'C', 'a', 't', 'e', 'g', 'o',
662 'r', 'i', 'e', 's', 0 };
664 TRACE("%s\n",debugstr_guid(rclsid));
666 if (rclsid == NULL || ppenumCATID == NULL)
667 return E_POINTER;
669 *ppenumCATID = COMCAT_CATID_IEnumGUID_Construct(rclsid, postfix);
670 if (*ppenumCATID == NULL) return E_OUTOFMEMORY;
671 return S_OK;
674 /**********************************************************************
675 * COMCAT_ICatRegister_Vtbl
677 static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
679 COMCAT_ICatRegister_QueryInterface,
680 COMCAT_ICatRegister_AddRef,
681 COMCAT_ICatRegister_Release,
682 COMCAT_ICatRegister_RegisterCategories,
683 COMCAT_ICatRegister_UnRegisterCategories,
684 COMCAT_ICatRegister_RegisterClassImplCategories,
685 COMCAT_ICatRegister_UnRegisterClassImplCategories,
686 COMCAT_ICatRegister_RegisterClassReqCategories,
687 COMCAT_ICatRegister_UnRegisterClassReqCategories
691 /**********************************************************************
692 * COMCAT_ICatInformation_Vtbl
694 static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
696 COMCAT_ICatInformation_QueryInterface,
697 COMCAT_ICatInformation_AddRef,
698 COMCAT_ICatInformation_Release,
699 COMCAT_ICatInformation_EnumCategories,
700 COMCAT_ICatInformation_GetCategoryDesc,
701 COMCAT_ICatInformation_EnumClassesOfCategories,
702 COMCAT_ICatInformation_IsClassOfCategories,
703 COMCAT_ICatInformation_EnumImplCategoriesOfClass,
704 COMCAT_ICatInformation_EnumReqCategoriesOfClass
707 /**********************************************************************
708 * COMCAT_IClassFactory_QueryInterface (also IUnknown)
710 static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
711 LPCLASSFACTORY iface,
712 REFIID riid,
713 LPVOID *ppvObj)
715 TRACE("%s\n",debugstr_guid(riid));
717 if (ppvObj == NULL) return E_POINTER;
719 if (IsEqualGUID(riid, &IID_IUnknown) ||
720 IsEqualGUID(riid, &IID_IClassFactory))
722 *ppvObj = iface;
723 IUnknown_AddRef(iface);
724 return S_OK;
727 return E_NOINTERFACE;
730 /**********************************************************************
731 * COMCAT_IClassFactory_AddRef (also IUnknown)
733 static ULONG WINAPI COMCAT_IClassFactory_AddRef(LPCLASSFACTORY iface)
735 return 2; /* non-heap based object */
738 /**********************************************************************
739 * COMCAT_IClassFactory_Release (also IUnknown)
741 static ULONG WINAPI COMCAT_IClassFactory_Release(LPCLASSFACTORY iface)
743 return 1; /* non-heap based object */
746 /**********************************************************************
747 * COMCAT_IClassFactory_CreateInstance
749 static HRESULT WINAPI COMCAT_IClassFactory_CreateInstance(
750 LPCLASSFACTORY iface,
751 LPUNKNOWN pUnkOuter,
752 REFIID riid,
753 LPVOID *ppvObj)
755 HRESULT res;
756 TRACE("%s\n",debugstr_guid(riid));
758 if (ppvObj == NULL) return E_POINTER;
760 /* Don't support aggregation (Windows doesn't) */
761 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
763 res = ICatRegister_QueryInterface(&COMCAT_ComCatMgr.ICatRegister_iface, riid, ppvObj);
764 if (SUCCEEDED(res)) {
765 return res;
768 return CLASS_E_CLASSNOTAVAILABLE;
771 /**********************************************************************
772 * COMCAT_IClassFactory_LockServer
774 static HRESULT WINAPI COMCAT_IClassFactory_LockServer(
775 LPCLASSFACTORY iface,
776 BOOL fLock)
778 FIXME("(%d), stub!\n",fLock);
779 return S_OK;
782 /**********************************************************************
783 * static ClassFactory instance
785 static const IClassFactoryVtbl ComCatCFVtbl =
787 COMCAT_IClassFactory_QueryInterface,
788 COMCAT_IClassFactory_AddRef,
789 COMCAT_IClassFactory_Release,
790 COMCAT_IClassFactory_CreateInstance,
791 COMCAT_IClassFactory_LockServer
794 static const IClassFactoryVtbl *ComCatCF = &ComCatCFVtbl;
796 HRESULT ComCatCF_Create(REFIID riid, LPVOID *ppv)
798 return IClassFactory_QueryInterface((IClassFactory *)&ComCatCF, riid, ppv);
801 /**********************************************************************
802 * IEnumCATEGORYINFO implementation
804 * This implementation is not thread-safe. The manager itself is, but
805 * I can't imagine a valid use of an enumerator in several threads.
807 typedef struct
809 const IEnumCATEGORYINFOVtbl *lpVtbl;
810 LONG ref;
811 LCID lcid;
812 HKEY key;
813 DWORD next_index;
814 } IEnumCATEGORYINFOImpl;
816 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(LPENUMCATEGORYINFO iface)
818 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
820 TRACE("\n");
822 return InterlockedIncrement(&This->ref);
825 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
826 LPENUMCATEGORYINFO iface,
827 REFIID riid,
828 LPVOID *ppvObj)
830 TRACE("%s\n",debugstr_guid(riid));
832 if (ppvObj == NULL) return E_POINTER;
834 if (IsEqualGUID(riid, &IID_IUnknown) ||
835 IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
837 *ppvObj = iface;
838 COMCAT_IEnumCATEGORYINFO_AddRef(iface);
839 return S_OK;
842 return E_NOINTERFACE;
845 static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(LPENUMCATEGORYINFO iface)
847 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
848 ULONG ref;
850 TRACE("\n");
852 ref = InterlockedDecrement(&This->ref);
853 if (ref == 0) {
854 if (This->key) RegCloseKey(This->key);
855 HeapFree(GetProcessHeap(), 0, This);
856 return 0;
858 return ref;
861 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
862 LPENUMCATEGORYINFO iface,
863 ULONG celt,
864 CATEGORYINFO *rgelt,
865 ULONG *pceltFetched)
867 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
868 ULONG fetched = 0;
870 TRACE("\n");
872 if (rgelt == NULL) return E_POINTER;
874 if (This->key) while (fetched < celt) {
875 LSTATUS res;
876 HRESULT hr;
877 WCHAR catid[39];
878 DWORD cName = 39;
879 HKEY subkey;
881 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
882 NULL, NULL, NULL, NULL);
883 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
884 ++(This->next_index);
886 hr = CLSIDFromString(catid, &rgelt->catid);
887 if (FAILED(hr)) continue;
889 res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
890 if (res != ERROR_SUCCESS) continue;
892 hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
893 rgelt->szDescription, 128);
894 RegCloseKey(subkey);
895 if (FAILED(hr)) continue;
897 rgelt->lcid = This->lcid;
898 ++fetched;
899 ++rgelt;
902 if (pceltFetched) *pceltFetched = fetched;
903 return fetched == celt ? S_OK : S_FALSE;
906 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
907 LPENUMCATEGORYINFO iface,
908 ULONG celt)
910 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
912 TRACE("\n");
914 This->next_index += celt;
915 /* This should return S_FALSE when there aren't celt elems to skip. */
916 return S_OK;
919 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(LPENUMCATEGORYINFO iface)
921 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
923 TRACE("\n");
925 This->next_index = 0;
926 return S_OK;
929 static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
930 LPENUMCATEGORYINFO iface,
931 IEnumCATEGORYINFO **ppenum)
933 IEnumCATEGORYINFOImpl *This = (IEnumCATEGORYINFOImpl *)iface;
934 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
935 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
936 'r', 'i', 'e', 's', 0 };
937 IEnumCATEGORYINFOImpl *new_this;
939 TRACE("\n");
941 if (ppenum == NULL) return E_POINTER;
943 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
944 if (new_this == NULL) return E_OUTOFMEMORY;
946 new_this->lpVtbl = This->lpVtbl;
947 new_this->ref = 1;
948 new_this->lcid = This->lcid;
949 /* FIXME: could we more efficiently use DuplicateHandle? */
950 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
951 new_this->next_index = This->next_index;
953 *ppenum = (LPENUMCATEGORYINFO)new_this;
954 return S_OK;
957 static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
959 COMCAT_IEnumCATEGORYINFO_QueryInterface,
960 COMCAT_IEnumCATEGORYINFO_AddRef,
961 COMCAT_IEnumCATEGORYINFO_Release,
962 COMCAT_IEnumCATEGORYINFO_Next,
963 COMCAT_IEnumCATEGORYINFO_Skip,
964 COMCAT_IEnumCATEGORYINFO_Reset,
965 COMCAT_IEnumCATEGORYINFO_Clone
968 static LPENUMCATEGORYINFO COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
970 IEnumCATEGORYINFOImpl *This;
972 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
973 if (This) {
974 static const WCHAR keyname[] = { 'C', 'o', 'm', 'p', 'o', 'n', 'e', 'n',
975 't', ' ', 'C', 'a', 't', 'e', 'g', 'o',
976 'r', 'i', 'e', 's', 0 };
978 This->lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
979 This->lcid = lcid;
980 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
982 return (LPENUMCATEGORYINFO)This;
985 /**********************************************************************
986 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
988 * This implementation is not thread-safe. The manager itself is, but
989 * I can't imagine a valid use of an enumerator in several threads.
991 typedef struct
993 const IEnumGUIDVtbl *lpVtbl;
994 LONG ref;
995 struct class_categories *categories;
996 HKEY key;
997 DWORD next_index;
998 } CLSID_IEnumGUIDImpl;
1000 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_AddRef(LPENUMGUID iface)
1002 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1003 TRACE("\n");
1005 return InterlockedIncrement(&This->ref);
1008 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_QueryInterface(
1009 LPENUMGUID iface,
1010 REFIID riid,
1011 LPVOID *ppvObj)
1013 TRACE("%s\n",debugstr_guid(riid));
1015 if (ppvObj == NULL) return E_POINTER;
1017 if (IsEqualGUID(riid, &IID_IUnknown) ||
1018 IsEqualGUID(riid, &IID_IEnumGUID))
1020 *ppvObj = iface;
1021 COMCAT_CLSID_IEnumGUID_AddRef(iface);
1022 return S_OK;
1025 return E_NOINTERFACE;
1028 static ULONG WINAPI COMCAT_CLSID_IEnumGUID_Release(LPENUMGUID iface)
1030 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1031 ULONG ref;
1033 TRACE("\n");
1035 ref = InterlockedDecrement(&This->ref);
1036 if (ref == 0) {
1037 if (This->key) RegCloseKey(This->key);
1038 HeapFree(GetProcessHeap(), 0, This->categories);
1039 HeapFree(GetProcessHeap(), 0, This);
1040 return 0;
1042 return ref;
1045 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
1046 LPENUMGUID iface,
1047 ULONG celt,
1048 GUID *rgelt,
1049 ULONG *pceltFetched)
1051 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1052 ULONG fetched = 0;
1054 TRACE("\n");
1056 if (rgelt == NULL) return E_POINTER;
1058 if (This->key) while (fetched < celt) {
1059 LSTATUS res;
1060 HRESULT hr;
1061 WCHAR clsid[39];
1062 DWORD cName = 39;
1063 HKEY subkey;
1065 res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
1066 NULL, NULL, NULL, NULL);
1067 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1068 ++(This->next_index);
1070 hr = CLSIDFromString(clsid, rgelt);
1071 if (FAILED(hr)) continue;
1073 res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
1074 if (res != ERROR_SUCCESS) continue;
1076 hr = COMCAT_IsClassOfCategories(subkey, This->categories);
1077 RegCloseKey(subkey);
1078 if (hr != S_OK) continue;
1080 ++fetched;
1081 ++rgelt;
1084 if (pceltFetched) *pceltFetched = fetched;
1085 return fetched == celt ? S_OK : S_FALSE;
1088 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Skip(
1089 LPENUMGUID iface,
1090 ULONG celt)
1092 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1094 TRACE("\n");
1096 This->next_index += celt;
1097 FIXME("Never returns S_FALSE\n");
1098 return S_OK;
1101 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Reset(LPENUMGUID iface)
1103 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1105 TRACE("\n");
1107 This->next_index = 0;
1108 return S_OK;
1111 static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
1112 LPENUMGUID iface,
1113 IEnumGUID **ppenum)
1115 CLSID_IEnumGUIDImpl *This = (CLSID_IEnumGUIDImpl *)iface;
1116 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1117 CLSID_IEnumGUIDImpl *new_this;
1118 DWORD size;
1120 TRACE("\n");
1122 if (ppenum == NULL) return E_POINTER;
1124 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1125 if (new_this == NULL) return E_OUTOFMEMORY;
1127 new_this->lpVtbl = This->lpVtbl;
1128 new_this->ref = 1;
1129 size = HeapSize(GetProcessHeap(), 0, This->categories);
1130 new_this->categories =
1131 HeapAlloc(GetProcessHeap(), 0, size);
1132 if (new_this->categories == NULL) {
1133 HeapFree(GetProcessHeap(), 0, new_this);
1134 return E_OUTOFMEMORY;
1136 memcpy(new_this->categories, This->categories, size);
1137 /* FIXME: could we more efficiently use DuplicateHandle? */
1138 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
1139 new_this->next_index = This->next_index;
1141 *ppenum = (LPENUMGUID)new_this;
1142 return S_OK;
1145 static const IEnumGUIDVtbl COMCAT_CLSID_IEnumGUID_Vtbl =
1147 COMCAT_CLSID_IEnumGUID_QueryInterface,
1148 COMCAT_CLSID_IEnumGUID_AddRef,
1149 COMCAT_CLSID_IEnumGUID_Release,
1150 COMCAT_CLSID_IEnumGUID_Next,
1151 COMCAT_CLSID_IEnumGUID_Skip,
1152 COMCAT_CLSID_IEnumGUID_Reset,
1153 COMCAT_CLSID_IEnumGUID_Clone
1156 static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *categories)
1158 CLSID_IEnumGUIDImpl *This;
1160 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1161 if (This) {
1162 static const WCHAR keyname[] = { 'C', 'L', 'S', 'I', 'D', 0 };
1164 This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
1165 This->categories = categories;
1166 RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
1168 return (LPENUMGUID)This;
1171 /**********************************************************************
1172 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
1174 * This implementation is not thread-safe. The manager itself is, but
1175 * I can't imagine a valid use of an enumerator in several threads.
1177 typedef struct
1179 const IEnumGUIDVtbl *lpVtbl;
1180 LONG ref;
1181 WCHAR keyname[68];
1182 HKEY key;
1183 DWORD next_index;
1184 } CATID_IEnumGUIDImpl;
1186 static ULONG WINAPI COMCAT_CATID_IEnumGUID_AddRef(LPENUMGUID iface)
1188 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1189 TRACE("\n");
1191 return InterlockedIncrement(&This->ref);
1194 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_QueryInterface(
1195 LPENUMGUID iface,
1196 REFIID riid,
1197 LPVOID *ppvObj)
1199 TRACE("%s\n",debugstr_guid(riid));
1201 if (ppvObj == NULL) return E_POINTER;
1203 if (IsEqualGUID(riid, &IID_IUnknown) ||
1204 IsEqualGUID(riid, &IID_IEnumGUID))
1206 *ppvObj = iface;
1207 COMCAT_CATID_IEnumGUID_AddRef(iface);
1208 return S_OK;
1211 return E_NOINTERFACE;
1214 static ULONG WINAPI COMCAT_CATID_IEnumGUID_Release(LPENUMGUID iface)
1216 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1217 ULONG ref;
1219 TRACE("\n");
1221 ref = InterlockedDecrement(&This->ref);
1222 if (ref == 0) {
1223 if (This->key) RegCloseKey(This->key);
1224 HeapFree(GetProcessHeap(), 0, This);
1225 return 0;
1227 return ref;
1230 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Next(
1231 LPENUMGUID iface,
1232 ULONG celt,
1233 GUID *rgelt,
1234 ULONG *pceltFetched)
1236 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1237 ULONG fetched = 0;
1239 TRACE("\n");
1241 if (rgelt == NULL) return E_POINTER;
1243 if (This->key) while (fetched < celt) {
1244 LSTATUS res;
1245 HRESULT hr;
1246 WCHAR catid[39];
1247 DWORD cName = 39;
1249 res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
1250 NULL, NULL, NULL, NULL);
1251 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
1252 ++(This->next_index);
1254 hr = CLSIDFromString(catid, rgelt);
1255 if (FAILED(hr)) continue;
1257 ++fetched;
1258 ++rgelt;
1261 if (pceltFetched) *pceltFetched = fetched;
1262 return fetched == celt ? S_OK : S_FALSE;
1265 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Skip(
1266 LPENUMGUID iface,
1267 ULONG celt)
1269 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1271 TRACE("\n");
1273 This->next_index += celt;
1274 FIXME("Never returns S_FALSE\n");
1275 return S_OK;
1278 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Reset(LPENUMGUID iface)
1280 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1282 TRACE("\n");
1284 This->next_index = 0;
1285 return S_OK;
1288 static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
1289 LPENUMGUID iface,
1290 IEnumGUID **ppenum)
1292 CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
1293 CATID_IEnumGUIDImpl *new_this;
1295 TRACE("\n");
1297 if (ppenum == NULL) return E_POINTER;
1299 new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1300 if (new_this == NULL) return E_OUTOFMEMORY;
1302 new_this->lpVtbl = This->lpVtbl;
1303 new_this->ref = 1;
1304 lstrcpyW(new_this->keyname, This->keyname);
1305 /* FIXME: could we more efficiently use DuplicateHandle? */
1306 RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
1307 new_this->next_index = This->next_index;
1309 *ppenum = (LPENUMGUID)new_this;
1310 return S_OK;
1313 static const IEnumGUIDVtbl COMCAT_CATID_IEnumGUID_Vtbl =
1315 COMCAT_CATID_IEnumGUID_QueryInterface,
1316 COMCAT_CATID_IEnumGUID_AddRef,
1317 COMCAT_CATID_IEnumGUID_Release,
1318 COMCAT_CATID_IEnumGUID_Next,
1319 COMCAT_CATID_IEnumGUID_Skip,
1320 COMCAT_CATID_IEnumGUID_Reset,
1321 COMCAT_CATID_IEnumGUID_Clone
1324 static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
1325 REFCLSID rclsid, LPCWSTR postfix)
1327 CATID_IEnumGUIDImpl *This;
1329 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1330 if (This) {
1331 WCHAR prefix[6] = { 'C', 'L', 'S', 'I', 'D', '\\' };
1333 This->lpVtbl = &COMCAT_CATID_IEnumGUID_Vtbl;
1334 memcpy(This->keyname, prefix, sizeof(prefix));
1335 StringFromGUID2(rclsid, This->keyname + 6, 39);
1336 lstrcpyW(This->keyname + 44, postfix);
1337 RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
1339 return (LPENUMGUID)This;