comcat.c 33.7 KB
Newer Older
1
/*
2
 * Comcat implementation
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Copyright (C) 2002 John K. Hohm
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
19 20
 */

21
#include <string.h>
22
#include <stdarg.h>
23

24 25 26 27 28 29 30 31 32 33
#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "winerror.h"

#include "ole2.h"
#include "comcat.h"
34 35
#include "compobj_private.h"

36 37 38 39
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(ole);

40 41 42
static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl;
static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl;

43 44
typedef struct
{
45 46
    ICatRegister ICatRegister_iface;
    ICatInformation ICatInformation_iface;
47
} ComCatMgrImpl;
48

49 50 51 52 53 54 55
/* static ComCatMgr instance */
static ComCatMgrImpl COMCAT_ComCatMgr =
{
    { &COMCAT_ICatRegister_Vtbl },
    { &COMCAT_ICatInformation_Vtbl }
};

56 57 58 59 60
struct class_categories
{
    ULONG   size;        /* total length, including structure itself */
    ULONG   impl_offset;
    ULONG   req_offset;
61 62
};

63 64 65
static HRESULT EnumCATEGORYINFO_Construct(LCID lcid, IEnumCATEGORYINFO **ret);
static HRESULT CLSIDEnumGUID_Construct(struct class_categories *class_categories, IEnumCLSID **ret);
static HRESULT CATIDEnumGUID_Construct(REFCLSID rclsid, LPCWSTR impl_req, IEnumCATID **ret);
66 67 68 69

/**********************************************************************
 * File-scope string constants
 */
70 71 72
static const WCHAR comcat_keyname[] = L"Component Categories";
static const WCHAR impl_keyname[] = L"Implemented Categories";
static const WCHAR req_keyname[] = L"Required Categories";
73

74 75 76 77 78 79 80 81 82
/**********************************************************************
 * COMCAT_RegisterClassCategories
 */
static HRESULT COMCAT_RegisterClassCategories(
    REFCLSID rclsid,
    LPCWSTR type,
    ULONG cCategories,
    const CATID *rgcatid)
{
83
    WCHAR keyname[CHARS_IN_GUID];
84 85 86 87 88 89
    HRESULT res;
    HKEY clsid_key, class_key, type_key;

    if (cCategories && rgcatid == NULL) return E_POINTER;

    /* Format the class key name. */
90
    res = StringFromGUID2(rclsid, keyname, CHARS_IN_GUID);
91 92 93
    if (FAILED(res)) return res;

    /* Create (or open) the CLSID key. */
94
    res = create_classes_key(HKEY_CLASSES_ROOT, L"CLSID", KEY_READ|KEY_WRITE, &clsid_key);
95 96 97
    if (res != ERROR_SUCCESS) return E_FAIL;

    /* Create (or open) the class key. */
98
    res = create_classes_key(clsid_key, keyname, KEY_READ|KEY_WRITE, &class_key);
99 100
    if (res == ERROR_SUCCESS) {
	/* Create (or open) the category type key. */
101
	res = create_classes_key(class_key, type, KEY_READ|KEY_WRITE, &type_key);
102 103 104 105 106
	if (res == ERROR_SUCCESS) {
	    for (; cCategories; --cCategories, ++rgcatid) {
		HKEY key;

		/* Format the category key name. */
107
		res = StringFromGUID2(rgcatid, keyname, CHARS_IN_GUID);
108 109 110
		if (FAILED(res)) continue;

		/* Do the register. */
111
		res = create_classes_key(type_key, keyname, KEY_READ|KEY_WRITE, &key);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
		if (res == ERROR_SUCCESS) RegCloseKey(key);
	    }
	    res = S_OK;
	} else res = E_FAIL;
	RegCloseKey(class_key);
    } else res = E_FAIL;
    RegCloseKey(clsid_key);

    return res;
}

/**********************************************************************
 * COMCAT_UnRegisterClassCategories
 */
static HRESULT COMCAT_UnRegisterClassCategories(
    REFCLSID rclsid,
    LPCWSTR type,
    ULONG cCategories,
    const CATID *rgcatid)
{
132
    WCHAR keyname[68] = L"CLSID\\";
133 134 135 136 137 138
    HRESULT res;
    HKEY type_key;

    if (cCategories && rgcatid == NULL) return E_POINTER;

    /* Format the class category type key name. */
139
    res = StringFromGUID2(rclsid, keyname + 6, CHARS_IN_GUID);
140 141 142 143 144
    if (FAILED(res)) return res;
    keyname[44] = '\\';
    lstrcpyW(keyname + 45, type);

    /* Open the class category type key. */
145
    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ|KEY_WRITE, &type_key);
146 147 148 149
    if (res != ERROR_SUCCESS) return E_FAIL;

    for (; cCategories; --cCategories, ++rgcatid) {
	/* Format the category key name. */
150
	res = StringFromGUID2(rgcatid, keyname, CHARS_IN_GUID);
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
	if (FAILED(res)) continue;

	/* Do the unregister. */
	RegDeleteKeyW(type_key, keyname);
    }
    RegCloseKey(type_key);

    return S_OK;
}

/**********************************************************************
 * COMCAT_GetCategoryDesc
 */
static HRESULT COMCAT_GetCategoryDesc(HKEY key, LCID lcid, PWCHAR pszDesc,
				      ULONG buf_wchars)
{
    WCHAR valname[5];
    HRESULT res;
    DWORD type, size = (buf_wchars - 1) * sizeof(WCHAR);

    if (pszDesc == NULL) return E_INVALIDARG;

    /* FIXME: lcid comparisons are more complex than this! */
174
    wsprintfW(valname, L"%lX", lcid);
175 176 177 178 179
    res = RegQueryValueExW(key, valname, 0, &type, (LPBYTE)pszDesc, &size);
    if (res != ERROR_SUCCESS || type != REG_SZ) {
	FIXME("Simplified lcid comparison\n");
	return CAT_E_NODESCRIPTION;
    }
180
    pszDesc[size / sizeof(WCHAR)] = 0;
181 182 183 184 185 186 187 188 189 190 191 192

    return S_OK;
}

/**********************************************************************
 * COMCAT_PrepareClassCategories
 */
static struct class_categories *COMCAT_PrepareClassCategories(
    ULONG impl_count, const CATID *impl_catids, ULONG req_count, const CATID *req_catids)
{
    struct class_categories *categories;
    WCHAR *strings;
193
    ULONG size;
194

195 196
    size = sizeof(struct class_categories) + ((impl_count + req_count)*CHARS_IN_GUID + 2)*sizeof(WCHAR);
    categories = HeapAlloc(GetProcessHeap(), 0, size);
197 198
    if (categories == NULL) return categories;

199 200 201 202
    categories->size = size;
    categories->impl_offset = sizeof(struct class_categories);
    categories->req_offset = categories->impl_offset + (impl_count*CHARS_IN_GUID + 1)*sizeof(WCHAR);

203 204
    strings = (WCHAR *)(categories + 1);
    while (impl_count--) {
205 206
	StringFromGUID2(impl_catids++, strings, CHARS_IN_GUID);
	strings += CHARS_IN_GUID;
207 208 209 210
    }
    *strings++ = 0;

    while (req_count--) {
211 212
	StringFromGUID2(req_catids++, strings, CHARS_IN_GUID);
	strings += CHARS_IN_GUID;
213 214 215 216 217 218 219 220 221 222 223 224 225
    }
    *strings++ = 0;

    return categories;
}

/**********************************************************************
 * COMCAT_IsClassOfCategories
 */
static HRESULT COMCAT_IsClassOfCategories(
    HKEY key,
    struct class_categories const* categories)
{
226
    const WCHAR *impl_strings, *req_strings;
227 228 229 230 231
    HKEY subkey;
    HRESULT res;
    DWORD index;
    LPCWSTR string;

232 233 234
    impl_strings = (WCHAR*)((BYTE*)categories + categories->impl_offset);
    req_strings  = (WCHAR*)((BYTE*)categories + categories->req_offset);

235
    /* Check that every given category is implemented by class. */
236
    if (*impl_strings) {
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) {
240
	    HKEY catkey;
241
	    res = open_classes_key(subkey, string, READ_CONTROL, &catkey);
242 243 244 245 246
	    if (res != ERROR_SUCCESS) {
		RegCloseKey(subkey);
		return S_FALSE;
	    }
	    RegCloseKey(catkey);
247
	}
248
	RegCloseKey(subkey);
249 250 251
    }

    /* Check that all categories required by class are given. */
252
    res = open_classes_key(key, req_keyname, KEY_READ, &subkey);
253 254
    if (res == ERROR_SUCCESS) {
	for (index = 0; ; ++index) {
255 256
	    WCHAR keyname[CHARS_IN_GUID];
	    DWORD size = CHARS_IN_GUID;
257 258 259 260

	    res = RegEnumKeyExW(subkey, index, keyname, &size,
				NULL, NULL, NULL, NULL);
	    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;
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	    if (!*string) {
		RegCloseKey(subkey);
		return S_FALSE;
	    }
	}
	RegCloseKey(subkey);
    }

    return S_OK;
}

/**********************************************************************
 * COMCAT_ICatRegister_QueryInterface
 */
static HRESULT WINAPI COMCAT_ICatRegister_QueryInterface(
    LPCATREGISTER iface,
    REFIID riid,
    LPVOID *ppvObj)
{
283
    TRACE("%s\n",debugstr_guid(riid));
284 285 286 287 288

    if (ppvObj == NULL) return E_POINTER;

    if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ICatRegister)) {
	*ppvObj = iface;
289
        ICatRegister_AddRef(iface);
290 291 292 293
	return S_OK;
    }

    if (IsEqualGUID(riid, &IID_ICatInformation)) {
294 295
        *ppvObj = &COMCAT_ComCatMgr.ICatInformation_iface;
        ICatRegister_AddRef(iface);
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
	return S_OK;
    }

    return E_NOINTERFACE;
}

/**********************************************************************
 * COMCAT_ICatRegister_AddRef
 */
static ULONG WINAPI COMCAT_ICatRegister_AddRef(LPCATREGISTER iface)
{
    return 2; /* non-heap based object */
}

/**********************************************************************
 * COMCAT_ICatRegister_Release
 */
static ULONG WINAPI COMCAT_ICatRegister_Release(LPCATREGISTER iface)
{
    return 1; /* non-heap based object */
}

/**********************************************************************
 * COMCAT_ICatRegister_RegisterCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
    LPCATREGISTER iface,
    ULONG cCategories,
    CATEGORYINFO *rgci)
{
    HKEY comcat_key;
    HRESULT res;

    TRACE("\n");

    if (cCategories && rgci == NULL)
	return E_POINTER;

    /* Create (or open) the component categories key. */
335
    res = create_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
336 337
    if (res != ERROR_SUCCESS) return E_FAIL;

338 339
    for (; cCategories; --cCategories, ++rgci)
    {
340
	WCHAR keyname[CHARS_IN_GUID];
341 342 343 344
	WCHAR valname[9];
	HKEY cat_key;

	/* 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 348 349
	if (res != ERROR_SUCCESS) continue;

	/* 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 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
		       (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR));

	RegCloseKey(cat_key);
    }

    RegCloseKey(comcat_key);
    return S_OK;
}

/**********************************************************************
 * COMCAT_ICatRegister_UnRegisterCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
    LPCATREGISTER iface,
    ULONG cCategories,
    CATID *rgcatid)
{
    HKEY comcat_key;
    HRESULT res;

    TRACE("\n");

    if (cCategories && rgcatid == NULL)
	return E_POINTER;

    /* Open the component categories key. */
378
    res = open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
379 380 381
    if (res != ERROR_SUCCESS) return E_FAIL;

    for (; cCategories; --cCategories, ++rgcatid) {
382
	WCHAR keyname[CHARS_IN_GUID];
383 384

	/* Delete the key for this category. */
385
	if (!StringFromGUID2(rgcatid, keyname, CHARS_IN_GUID)) continue;
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
	RegDeleteKeyW(comcat_key, keyname);
    }

    RegCloseKey(comcat_key);
    return S_OK;
}

/**********************************************************************
 * COMCAT_ICatRegister_RegisterClassImplCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassImplCategories(
    LPCATREGISTER iface,
    REFCLSID rclsid,
    ULONG cCategories,
    CATID *rgcatid)
{
    TRACE("\n");

    return COMCAT_RegisterClassCategories(
	rclsid,	impl_keyname, cCategories, rgcatid);
}

/**********************************************************************
 * COMCAT_ICatRegister_UnRegisterClassImplCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassImplCategories(
    LPCATREGISTER iface,
    REFCLSID rclsid,
    ULONG cCategories,
    CATID *rgcatid)
{
    TRACE("\n");

    return COMCAT_UnRegisterClassCategories(
	rclsid, impl_keyname, cCategories, rgcatid);
}

/**********************************************************************
 * COMCAT_ICatRegister_RegisterClassReqCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_RegisterClassReqCategories(
    LPCATREGISTER iface,
    REFCLSID rclsid,
    ULONG cCategories,
    CATID *rgcatid)
{
    TRACE("\n");

    return COMCAT_RegisterClassCategories(
	rclsid, req_keyname, cCategories, rgcatid);
}

/**********************************************************************
 * COMCAT_ICatRegister_UnRegisterClassReqCategories
 */
static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterClassReqCategories(
    LPCATREGISTER iface,
    REFCLSID rclsid,
    ULONG cCategories,
    CATID *rgcatid)
{
    TRACE("\n");

    return COMCAT_UnRegisterClassCategories(
	rclsid, req_keyname, cCategories, rgcatid);
}

453 454 455 456 457 458 459 460
/**********************************************************************
 * COMCAT_ICatInformation_QueryInterface
 */
static HRESULT WINAPI COMCAT_ICatInformation_QueryInterface(
    LPCATINFORMATION iface,
    REFIID riid,
    LPVOID *ppvObj)
{
461
    return ICatRegister_QueryInterface(&COMCAT_ComCatMgr.ICatRegister_iface, riid, ppvObj);
462 463 464 465 466 467 468
}

/**********************************************************************
 * COMCAT_ICatInformation_AddRef
 */
static ULONG WINAPI COMCAT_ICatInformation_AddRef(LPCATINFORMATION iface)
{
469
    return ICatRegister_AddRef(&COMCAT_ComCatMgr.ICatRegister_iface);
470 471 472 473 474 475 476
}

/**********************************************************************
 * COMCAT_ICatInformation_Release
 */
static ULONG WINAPI COMCAT_ICatInformation_Release(LPCATINFORMATION iface)
{
477
    return ICatRegister_Release(&COMCAT_ComCatMgr.ICatRegister_iface);
478 479 480 481 482 483 484 485
}

/**********************************************************************
 * COMCAT_ICatInformation_EnumCategories
 */
static HRESULT WINAPI COMCAT_ICatInformation_EnumCategories(
    LPCATINFORMATION iface,
    LCID lcid,
486
    IEnumCATEGORYINFO **ppenumCatInfo)
487
{
488
    TRACE("\n");
489

490
    if (ppenumCatInfo == NULL) return E_POINTER;
491

492
    return EnumCATEGORYINFO_Construct(lcid, ppenumCatInfo);
493 494 495 496 497 498 499 500 501 502 503
}

/**********************************************************************
 * COMCAT_ICatInformation_GetCategoryDesc
 */
static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
    LPCATINFORMATION iface,
    REFCATID rcatid,
    LCID lcid,
    PWCHAR *ppszDesc)
{
504
    WCHAR keyname[60] = L"Component Categories\\";
505 506
    HKEY key;
    HRESULT res;
507

508
    TRACE("CATID: %s LCID: %x\n",debugstr_guid(rcatid), lcid);
509 510 511 512

    if (rcatid == NULL || ppszDesc == NULL) return E_INVALIDARG;

    /* 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 516 517
    if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;

    /* Allocate a sensible amount of memory for the description. */
518
    *ppszDesc = CoTaskMemAlloc(128 * sizeof(WCHAR));
519 520 521 522 523 524 525 526 527 528 529 530 531 532
    if (*ppszDesc == NULL) {
	RegCloseKey(key);
	return E_OUTOFMEMORY;
    }

    /* Get the description, and make sure it's null terminated. */
    res = COMCAT_GetCategoryDesc(key, lcid, *ppszDesc, 128);
    RegCloseKey(key);
    if (FAILED(res)) {
	CoTaskMemFree(*ppszDesc);
	return res;
    }

    return S_OK;
533 534 535 536 537 538 539 540 541 542 543 544 545
}

/**********************************************************************
 * COMCAT_ICatInformation_EnumClassesOfCategories
 */
static HRESULT WINAPI COMCAT_ICatInformation_EnumClassesOfCategories(
    LPCATINFORMATION iface,
    ULONG cImplemented,
    CATID *rgcatidImpl,
    ULONG cRequired,
    CATID *rgcatidReq,
    LPENUMCLSID *ppenumCLSID)
{
546
    struct class_categories *categories;
547
    HRESULT hr;
548 549

    TRACE("\n");
550

551
	if (cImplemented == (ULONG)-1)
552
		cImplemented = 0;
553
	if (cRequired == (ULONG)-1)
554
		cRequired = 0;
555

556
    if (ppenumCLSID == NULL ||
557 558 559 560 561 562
	(cImplemented && rgcatidImpl == NULL) ||
	(cRequired && rgcatidReq == NULL)) return E_POINTER;

    categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
					       cRequired, rgcatidReq);
    if (categories == NULL) return E_OUTOFMEMORY;
563 564 565 566

    hr = CLSIDEnumGUID_Construct(categories, ppenumCLSID);
    if (FAILED(hr))
    {
567
	HeapFree(GetProcessHeap(), 0, categories);
568
	return hr;
569
    }
570 571

    return hr;
572 573 574 575 576 577 578 579 580 581 582 583 584
}

/**********************************************************************
 * COMCAT_ICatInformation_IsClassOfCategories
 */
static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
    LPCATINFORMATION iface,
    REFCLSID rclsid,
    ULONG cImplemented,
    CATID *rgcatidImpl,
    ULONG cRequired,
    CATID *rgcatidReq)
{
585
    WCHAR keyname[45] = L"CLSID\\";
586 587 588 589
    HRESULT res;
    struct class_categories *categories;
    HKEY key;

590
    if (TRACE_ON(ole)) {
591
	ULONG count;
592
	TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented);
593
	for (count = 0; count < cImplemented; ++count)
594 595
	    TRACE("    %s\n",debugstr_guid(&rgcatidImpl[count]));
	TRACE("Required %u\n",cRequired);
596
	for (count = 0; count < cRequired; ++count)
597
	    TRACE("    %s\n",debugstr_guid(&rgcatidReq[count]));
598 599 600 601 602
    }

    if ((cImplemented && rgcatidImpl == NULL) ||
	(cRequired && rgcatidReq == NULL)) return E_POINTER;

603
    res = StringFromGUID2(rclsid, keyname + 6, CHARS_IN_GUID);
604 605 606 607 608 609
    if (FAILED(res)) return res;

    categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl,
					       cRequired, rgcatidReq);
    if (categories == NULL) return E_OUTOFMEMORY;

610
    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
611 612 613 614
    if (res == ERROR_SUCCESS) {
	res = COMCAT_IsClassOfCategories(key, categories);
	RegCloseKey(key);
    } else res = S_FALSE;
615

616 617 618
    HeapFree(GetProcessHeap(), 0, categories);

    return res;
619 620 621 622 623 624 625 626 627 628
}

/**********************************************************************
 * COMCAT_ICatInformation_EnumImplCategoriesOfClass
 */
static HRESULT WINAPI COMCAT_ICatInformation_EnumImplCategoriesOfClass(
    LPCATINFORMATION iface,
    REFCLSID rclsid,
    LPENUMCATID *ppenumCATID)
{
629
    TRACE("%s\n",debugstr_guid(rclsid));
630

631
    if (rclsid == NULL || ppenumCATID == NULL)
632
	return E_POINTER;
633

634
    return CATIDEnumGUID_Construct(rclsid, L"\\Implemented Categories", ppenumCATID);
635 636 637 638 639 640 641 642 643 644
}

/**********************************************************************
 * COMCAT_ICatInformation_EnumReqCategoriesOfClass
 */
static HRESULT WINAPI COMCAT_ICatInformation_EnumReqCategoriesOfClass(
    LPCATINFORMATION iface,
    REFCLSID rclsid,
    LPENUMCATID *ppenumCATID)
{
645
    TRACE("%s\n",debugstr_guid(rclsid));
646

647
    if (rclsid == NULL || ppenumCATID == NULL)
648 649
	return E_POINTER;

650
    return CATIDEnumGUID_Construct(rclsid, L"\\Required Categories", ppenumCATID);
651 652
}

653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
/**********************************************************************
 * COMCAT_ICatRegister_Vtbl
 */
static const ICatRegisterVtbl COMCAT_ICatRegister_Vtbl =
{
    COMCAT_ICatRegister_QueryInterface,
    COMCAT_ICatRegister_AddRef,
    COMCAT_ICatRegister_Release,
    COMCAT_ICatRegister_RegisterCategories,
    COMCAT_ICatRegister_UnRegisterCategories,
    COMCAT_ICatRegister_RegisterClassImplCategories,
    COMCAT_ICatRegister_UnRegisterClassImplCategories,
    COMCAT_ICatRegister_RegisterClassReqCategories,
    COMCAT_ICatRegister_UnRegisterClassReqCategories
};


670 671 672
/**********************************************************************
 * COMCAT_ICatInformation_Vtbl
 */
673
static const ICatInformationVtbl COMCAT_ICatInformation_Vtbl =
674 675 676 677 678 679 680 681 682 683 684
{
    COMCAT_ICatInformation_QueryInterface,
    COMCAT_ICatInformation_AddRef,
    COMCAT_ICatInformation_Release,
    COMCAT_ICatInformation_EnumCategories,
    COMCAT_ICatInformation_GetCategoryDesc,
    COMCAT_ICatInformation_EnumClassesOfCategories,
    COMCAT_ICatInformation_IsClassOfCategories,
    COMCAT_ICatInformation_EnumImplCategoriesOfClass,
    COMCAT_ICatInformation_EnumReqCategoriesOfClass
};
685

686
HRESULT WINAPI ComCat_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
687 688
{
    HRESULT res;
689
    TRACE("%s\n",debugstr_guid(riid));
690 691 692 693 694 695

    if (ppvObj == NULL) return E_POINTER;

    /* Don't support aggregation (Windows doesn't) */
    if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;

696
    res = ICatRegister_QueryInterface(&COMCAT_ComCatMgr.ICatRegister_iface, riid, ppvObj);
697 698 699 700 701 702 703
    if (SUCCEEDED(res)) {
	return res;
    }

    return CLASS_E_CLASSNOTAVAILABLE;
}

704 705 706 707 708 709 710 711
/**********************************************************************
 * IEnumCATEGORYINFO implementation
 *
 * This implementation is not thread-safe.  The manager itself is, but
 * I can't imagine a valid use of an enumerator in several threads.
 */
typedef struct
{
712
    IEnumCATEGORYINFO IEnumCATEGORYINFO_iface;
713
    LONG  ref;
714 715 716 717 718
    LCID  lcid;
    HKEY  key;
    DWORD next_index;
} IEnumCATEGORYINFOImpl;

719
static inline IEnumCATEGORYINFOImpl *impl_from_IEnumCATEGORYINFO(IEnumCATEGORYINFO *iface)
720
{
721 722 723 724 725 726
    return CONTAINING_RECORD(iface, IEnumCATEGORYINFOImpl, IEnumCATEGORYINFO_iface);
}

static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_AddRef(IEnumCATEGORYINFO *iface)
{
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
727

728 729
    TRACE("\n");

730
    return InterlockedIncrement(&This->ref);
731 732 733
}

static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_QueryInterface(
734
    IEnumCATEGORYINFO *iface,
735 736 737
    REFIID riid,
    LPVOID *ppvObj)
{
738
    TRACE("%s\n",debugstr_guid(riid));
739

740
    if (ppvObj == NULL) return E_POINTER;
741 742 743 744

    if (IsEqualGUID(riid, &IID_IUnknown) ||
	IsEqualGUID(riid, &IID_IEnumCATEGORYINFO))
    {
745
        *ppvObj = iface;
746 747 748 749 750 751 752
	COMCAT_IEnumCATEGORYINFO_AddRef(iface);
	return S_OK;
    }

    return E_NOINTERFACE;
}

753
static ULONG WINAPI COMCAT_IEnumCATEGORYINFO_Release(IEnumCATEGORYINFO *iface)
754
{
755
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
756 757
    ULONG ref;

758 759
    TRACE("\n");

760 761
    ref = InterlockedDecrement(&This->ref);
    if (ref == 0) {
762 763 764 765
	if (This->key) RegCloseKey(This->key);
	HeapFree(GetProcessHeap(), 0, This);
	return 0;
    }
766
    return ref;
767 768 769
}

static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
770
    IEnumCATEGORYINFO *iface,
771 772 773 774
    ULONG celt,
    CATEGORYINFO *rgelt,
    ULONG *pceltFetched)
{
775
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
776 777 778 779
    ULONG fetched = 0;

    TRACE("\n");

780
    if (rgelt == NULL) return E_POINTER;
781 782

    if (This->key) while (fetched < celt) {
783 784
	LSTATUS res;
	HRESULT hr;
785 786
	WCHAR catid[CHARS_IN_GUID];
	DWORD cName = CHARS_IN_GUID;
787 788 789 790 791 792 793
	HKEY subkey;

	res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
			    NULL, NULL, NULL, NULL);
	if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
	++(This->next_index);

794 795
	hr = CLSIDFromString(catid, &rgelt->catid);
	if (FAILED(hr)) continue;
796

797
	res = open_classes_key(This->key, catid, KEY_READ, &subkey);
798 799
	if (res != ERROR_SUCCESS) continue;

800 801
	hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
				    rgelt->szDescription, 128);
802
	RegCloseKey(subkey);
803
	if (FAILED(hr)) continue;
804 805 806 807 808 809 810 811 812 813 814

	rgelt->lcid = This->lcid;
	++fetched;
	++rgelt;
    }

    if (pceltFetched) *pceltFetched = fetched;
    return fetched == celt ? S_OK : S_FALSE;
}

static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Skip(
815
    IEnumCATEGORYINFO *iface,
816 817
    ULONG celt)
{
818
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
819 820

    TRACE("\n");
821

822 823 824
    This->next_index += celt;
    /* This should return S_FALSE when there aren't celt elems to skip. */
    return S_OK;
825 826
}

827
static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Reset(IEnumCATEGORYINFO *iface)
828
{
829
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
830 831

    TRACE("\n");
832

833 834
    This->next_index = 0;
    return S_OK;
835 836 837
}

static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
838
    IEnumCATEGORYINFO *iface,
839 840
    IEnumCATEGORYINFO **ppenum)
{
841
    IEnumCATEGORYINFOImpl *This = impl_from_IEnumCATEGORYINFO(iface);
842
    IEnumCATEGORYINFOImpl *new_this;
843

844 845
    TRACE("\n");

846
    if (ppenum == NULL) return E_POINTER;
847

848
    new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
849 850
    if (new_this == NULL) return E_OUTOFMEMORY;

851
    new_this->IEnumCATEGORYINFO_iface = This->IEnumCATEGORYINFO_iface;
852 853 854
    new_this->ref = 1;
    new_this->lcid = This->lcid;
    /* FIXME: could we more efficiently use DuplicateHandle? */
855
    open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ, &new_this->key);
856 857
    new_this->next_index = This->next_index;

858
    *ppenum = &new_this->IEnumCATEGORYINFO_iface;
859
    return S_OK;
860 861
}

862
static const IEnumCATEGORYINFOVtbl COMCAT_IEnumCATEGORYINFO_Vtbl =
863 864 865 866 867 868 869 870 871 872
{
    COMCAT_IEnumCATEGORYINFO_QueryInterface,
    COMCAT_IEnumCATEGORYINFO_AddRef,
    COMCAT_IEnumCATEGORYINFO_Release,
    COMCAT_IEnumCATEGORYINFO_Next,
    COMCAT_IEnumCATEGORYINFO_Skip,
    COMCAT_IEnumCATEGORYINFO_Reset,
    COMCAT_IEnumCATEGORYINFO_Clone
};

873
static HRESULT EnumCATEGORYINFO_Construct(LCID lcid, IEnumCATEGORYINFO **ret)
874 875 876
{
    IEnumCATEGORYINFOImpl *This;

877 878
    *ret = NULL;

879
    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumCATEGORYINFOImpl));
880 881 882 883 884
    if (!This) return E_OUTOFMEMORY;

    This->IEnumCATEGORYINFO_iface.lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
    This->ref = 1;
    This->lcid = lcid;
885
    open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ, &This->key);
886 887 888

    *ret = &This->IEnumCATEGORYINFO_iface;
    return S_OK;
889 890
}

891 892 893 894 895 896 897 898
/**********************************************************************
 * ClassesOfCategories IEnumCLSID (IEnumGUID) implementation
 *
 * This implementation is not thread-safe.  The manager itself is, but
 * I can't imagine a valid use of an enumerator in several threads.
 */
typedef struct
{
899
    IEnumGUID IEnumGUID_iface;
900
    LONG  ref;
901
    struct class_categories *categories;
902 903 904 905
    HKEY  key;
    DWORD next_index;
} CLSID_IEnumGUIDImpl;

906
static inline CLSID_IEnumGUIDImpl *impl_from_IEnumCLSID(IEnumGUID *iface)
907
{
908
    return CONTAINING_RECORD(iface, CLSID_IEnumGUIDImpl, IEnumGUID_iface);
909 910
}

911 912
static HRESULT WINAPI CLSIDEnumGUID_QueryInterface(
    IEnumGUID *iface,
913 914 915
    REFIID riid,
    LPVOID *ppvObj)
{
916
    TRACE("%s\n",debugstr_guid(riid));
917

918
    if (ppvObj == NULL) return E_POINTER;
919 920 921 922

    if (IsEqualGUID(riid, &IID_IUnknown) ||
	IsEqualGUID(riid, &IID_IEnumGUID))
    {
923
        *ppvObj = iface;
924
	IEnumGUID_AddRef(iface);
925 926 927 928 929 930
	return S_OK;
    }

    return E_NOINTERFACE;
}

931 932 933 934 935 936 937 938 939
static ULONG WINAPI CLSIDEnumGUID_AddRef(IEnumGUID *iface)
{
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
    TRACE("\n");

    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI CLSIDEnumGUID_Release(IEnumGUID *iface)
940
{
941
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
942 943
    ULONG ref;

944 945
    TRACE("\n");

946 947
    ref = InterlockedDecrement(&This->ref);
    if (ref == 0) {
948
	if (This->key) RegCloseKey(This->key);
949
        HeapFree(GetProcessHeap(), 0, This->categories);
950 951 952
	HeapFree(GetProcessHeap(), 0, This);
	return 0;
    }
953
    return ref;
954 955
}

956 957
static HRESULT WINAPI CLSIDEnumGUID_Next(
    IEnumGUID *iface,
958 959 960 961
    ULONG celt,
    GUID *rgelt,
    ULONG *pceltFetched)
{
962
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
963 964 965 966
    ULONG fetched = 0;

    TRACE("\n");

967
    if (rgelt == NULL) return E_POINTER;
968 969

    if (This->key) while (fetched < celt) {
970 971
	LSTATUS res;
	HRESULT hr;
972 973
	WCHAR clsid[CHARS_IN_GUID];
	DWORD cName = CHARS_IN_GUID;
974 975 976 977 978 979 980
	HKEY subkey;

	res = RegEnumKeyExW(This->key, This->next_index, clsid, &cName,
			    NULL, NULL, NULL, NULL);
	if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
	++(This->next_index);

981 982
	hr = CLSIDFromString(clsid, rgelt);
	if (FAILED(hr)) continue;
983

984
	res = open_classes_key(This->key, clsid, KEY_READ, &subkey);
985 986
	if (res != ERROR_SUCCESS) continue;

987
	hr = COMCAT_IsClassOfCategories(subkey, This->categories);
988
	RegCloseKey(subkey);
989
	if (hr != S_OK) continue;
990 991 992 993 994 995 996 997 998

	++fetched;
	++rgelt;
    }

    if (pceltFetched) *pceltFetched = fetched;
    return fetched == celt ? S_OK : S_FALSE;
}

999 1000
static HRESULT WINAPI CLSIDEnumGUID_Skip(
    IEnumGUID *iface,
1001 1002
    ULONG celt)
{
1003
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
1004 1005 1006 1007 1008 1009 1010 1011

    TRACE("\n");

    This->next_index += celt;
    FIXME("Never returns S_FALSE\n");
    return S_OK;
}

1012
static HRESULT WINAPI CLSIDEnumGUID_Reset(IEnumGUID *iface)
1013
{
1014
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
1015 1016 1017 1018 1019 1020 1021

    TRACE("\n");

    This->next_index = 0;
    return S_OK;
}

1022 1023
static HRESULT WINAPI CLSIDEnumGUID_Clone(
    IEnumGUID *iface,
1024 1025
    IEnumGUID **ppenum)
{
1026
    CLSID_IEnumGUIDImpl *This = impl_from_IEnumCLSID(iface);
1027
    CLSID_IEnumGUIDImpl *cloned;
1028

1029
    TRACE("(%p)->(%p)\n", This, ppenum);
1030

1031
    if (ppenum == NULL) return E_POINTER;
1032

1033
    *ppenum = NULL;
1034

1035 1036 1037 1038 1039 1040 1041 1042 1043
    cloned = HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID_IEnumGUIDImpl));
    if (cloned == NULL) return E_OUTOFMEMORY;

    cloned->IEnumGUID_iface.lpVtbl = This->IEnumGUID_iface.lpVtbl;
    cloned->ref = 1;

    cloned->categories = HeapAlloc(GetProcessHeap(), 0, This->categories->size);
    if (cloned->categories == NULL) {
	HeapFree(GetProcessHeap(), 0, cloned);
1044 1045
	return E_OUTOFMEMORY;
    }
1046 1047 1048
    memcpy(cloned->categories, This->categories, This->categories->size);

    cloned->key = NULL;
1049
    open_classes_key(HKEY_CLASSES_ROOT, L"CLSID", KEY_READ, &cloned->key);
1050
    cloned->next_index = This->next_index;
1051

1052
    *ppenum = &cloned->IEnumGUID_iface;
1053 1054 1055
    return S_OK;
}

1056
static const IEnumGUIDVtbl CLSIDEnumGUIDVtbl =
1057
{
1058 1059 1060 1061 1062 1063 1064
    CLSIDEnumGUID_QueryInterface,
    CLSIDEnumGUID_AddRef,
    CLSIDEnumGUID_Release,
    CLSIDEnumGUID_Next,
    CLSIDEnumGUID_Skip,
    CLSIDEnumGUID_Reset,
    CLSIDEnumGUID_Clone
1065 1066
};

1067
static HRESULT CLSIDEnumGUID_Construct(struct class_categories *categories, IEnumCLSID **ret)
1068 1069 1070
{
    CLSID_IEnumGUIDImpl *This;

1071 1072
    *ret = NULL;

1073
    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLSID_IEnumGUIDImpl));
1074
    if (!This) return E_OUTOFMEMORY;
1075

1076 1077 1078
    This->IEnumGUID_iface.lpVtbl = &CLSIDEnumGUIDVtbl;
    This->ref = 1;
    This->categories = categories;
1079
    open_classes_key(HKEY_CLASSES_ROOT, L"CLSID", KEY_READ, &This->key);
1080 1081 1082 1083

    *ret = &This->IEnumGUID_iface;

    return S_OK;
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
}

/**********************************************************************
 * CategoriesOfClass IEnumCATID (IEnumGUID) implementation
 *
 * This implementation is not thread-safe.  The manager itself is, but
 * I can't imagine a valid use of an enumerator in several threads.
 */
typedef struct
{
1094
    IEnumGUID IEnumGUID_iface;
1095
    LONG  ref;
1096 1097 1098 1099 1100
    WCHAR keyname[68];
    HKEY  key;
    DWORD next_index;
} CATID_IEnumGUIDImpl;

1101
static inline CATID_IEnumGUIDImpl *impl_from_IEnumCATID(IEnumGUID *iface)
1102
{
1103
    return CONTAINING_RECORD(iface, CATID_IEnumGUIDImpl, IEnumGUID_iface);
1104 1105
}

1106 1107
static HRESULT WINAPI CATIDEnumGUID_QueryInterface(
    IEnumGUID *iface,
1108 1109 1110
    REFIID riid,
    LPVOID *ppvObj)
{
1111
    TRACE("%s\n",debugstr_guid(riid));
1112

1113
    if (ppvObj == NULL) return E_POINTER;
1114 1115 1116 1117

    if (IsEqualGUID(riid, &IID_IUnknown) ||
	IsEqualGUID(riid, &IID_IEnumGUID))
    {
1118
        *ppvObj = iface;
1119
	IEnumGUID_AddRef(iface);
1120 1121 1122 1123 1124 1125
	return S_OK;
    }

    return E_NOINTERFACE;
}

1126 1127 1128 1129 1130 1131 1132 1133 1134
static ULONG WINAPI CATIDEnumGUID_AddRef(IEnumGUID *iface)
{
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
    TRACE("\n");

    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI CATIDEnumGUID_Release(IEnumGUID *iface)
1135
{
1136
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
1137 1138
    ULONG ref;

1139 1140
    TRACE("\n");

1141 1142
    ref = InterlockedDecrement(&This->ref);
    if (ref == 0) {
1143 1144 1145 1146
	if (This->key) RegCloseKey(This->key);
	HeapFree(GetProcessHeap(), 0, This);
	return 0;
    }
1147
    return ref;
1148 1149
}

1150 1151
static HRESULT WINAPI CATIDEnumGUID_Next(
    IEnumGUID *iface,
1152 1153 1154 1155
    ULONG celt,
    GUID *rgelt,
    ULONG *pceltFetched)
{
1156
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
1157 1158 1159 1160
    ULONG fetched = 0;

    TRACE("\n");

1161
    if (rgelt == NULL) return E_POINTER;
1162 1163

    if (This->key) while (fetched < celt) {
1164 1165
	LSTATUS res;
	HRESULT hr;
1166 1167
	WCHAR catid[CHARS_IN_GUID];
	DWORD cName = CHARS_IN_GUID;
1168 1169 1170 1171 1172 1173

	res = RegEnumKeyExW(This->key, This->next_index, catid, &cName,
			    NULL, NULL, NULL, NULL);
	if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) break;
	++(This->next_index);

1174 1175
	hr = CLSIDFromString(catid, rgelt);
	if (FAILED(hr)) continue;
1176 1177 1178 1179 1180 1181 1182 1183 1184

	++fetched;
	++rgelt;
    }

    if (pceltFetched) *pceltFetched = fetched;
    return fetched == celt ? S_OK : S_FALSE;
}

1185 1186
static HRESULT WINAPI CATIDEnumGUID_Skip(
    IEnumGUID *iface,
1187 1188
    ULONG celt)
{
1189
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
1190 1191 1192 1193 1194 1195 1196 1197

    TRACE("\n");

    This->next_index += celt;
    FIXME("Never returns S_FALSE\n");
    return S_OK;
}

1198
static HRESULT WINAPI CATIDEnumGUID_Reset(IEnumGUID *iface)
1199
{
1200
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
1201 1202 1203 1204 1205 1206 1207

    TRACE("\n");

    This->next_index = 0;
    return S_OK;
}

1208 1209
static HRESULT WINAPI CATIDEnumGUID_Clone(
    IEnumGUID *iface,
1210 1211
    IEnumGUID **ppenum)
{
1212
    CATID_IEnumGUIDImpl *This = impl_from_IEnumCATID(iface);
1213 1214 1215 1216
    CATID_IEnumGUIDImpl *new_this;

    TRACE("\n");

1217
    if (ppenum == NULL) return E_POINTER;
1218

1219
    new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
1220 1221
    if (new_this == NULL) return E_OUTOFMEMORY;

1222
    new_this->IEnumGUID_iface.lpVtbl = This->IEnumGUID_iface.lpVtbl;
1223 1224 1225
    new_this->ref = 1;
    lstrcpyW(new_this->keyname, This->keyname);
    /* FIXME: could we more efficiently use DuplicateHandle? */
1226
    open_classes_key(HKEY_CLASSES_ROOT, new_this->keyname, KEY_READ, &new_this->key);
1227 1228
    new_this->next_index = This->next_index;

1229
    *ppenum = &new_this->IEnumGUID_iface;
1230 1231 1232
    return S_OK;
}

1233
static const IEnumGUIDVtbl CATIDEnumGUIDVtbl =
1234
{
1235 1236 1237 1238 1239 1240 1241
    CATIDEnumGUID_QueryInterface,
    CATIDEnumGUID_AddRef,
    CATIDEnumGUID_Release,
    CATIDEnumGUID_Next,
    CATIDEnumGUID_Skip,
    CATIDEnumGUID_Reset,
    CATIDEnumGUID_Clone
1242 1243
};

1244
static HRESULT CATIDEnumGUID_Construct(REFCLSID rclsid, LPCWSTR postfix, IEnumGUID **ret)
1245
{
1246
    WCHAR keyname[100], clsidW[CHARS_IN_GUID];
1247 1248
    CATID_IEnumGUIDImpl *This;

1249 1250 1251 1252 1253 1254 1255 1256 1257
    *ret = NULL;

    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
    if (!This) return E_OUTOFMEMORY;

    StringFromGUID2(rclsid, clsidW, CHARS_IN_GUID);

    This->IEnumGUID_iface.lpVtbl = &CATIDEnumGUIDVtbl;
    This->ref = 1;
1258
    lstrcpyW(keyname, L"CLSID\\");
1259 1260
    lstrcatW(keyname, clsidW);
    lstrcatW(keyname, postfix);
1261 1262 1263 1264 1265

    open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);

    *ret = &This->IEnumGUID_iface;
    return S_OK;
1266
}