Click to See Complete Forum and Search --> : Class ID, Category


Jim Bassett
May 18th, 1999, 12:59 PM
I have seen a Client application that finds particuliar COM components, obtains a string from those components descripting the COM's function. I was told the client is using the component's Class ID and Category to look in the registry to ID components that fit a certain way. I have not found any reference to this in any books I have, so can someone direct me to what this is.

Thanks

Jim Bassett

David L Hill
May 18th, 1999, 02:56 PM
To determine if an object supports a particular functionality, you could query for all the interfaces in the group, but this would add the overhead of creating the object, etc and would not give you the whole story. So you have categories that allow you to determine what objects support a specific functionality.

An object can register a category as required or implemented. The required indicates that the container must support this behaviour (might need a sink interface). The implemented indicates the object supports the behavior, but containers that do not use the behavior can still use the object.

To register the category use the category map macros.

Example:
BEGIN_CATEGORY_MAP(CSample)
IMPLEMENTED_CATEGORY(CATID_Sample)
END_CATEGORY_MAP()

The CATID_Sample is a uuid that you have generated.

A program wanting to instantiate objects belonging to the category, can get an enumerator and find the classids.

Example:
ICatInformationPtr pCatInfo (CLSID_StdComponentCategoriesMgr);
CATID cat = CATID_Sample;
IEnumGUIDPtr pEnum;
pCatInfo->EnumClassesOfCategories(1, &cat, 0, NULL, &pEnum);
CLSID clsid;
ULONG ulFetched = 0;
if (SUCCEEDED(pEnum->Next(1, &clsid, &ulFetched)) && ulFetched > 0)
{ ... }

Here I have just gotten the first classid with an implemented category (the third and fourth parameters are for required). You would normally loop and retrieve a group a time.

I have not found alot of information, but the book by Wrox Press, Professional ATL COM Programming by Dr. Richard Grimes has a section on categories.