Problem:
I want to write an application that supports ActiveX document Plug-ins (Plug-ins). To create a menu of installed Plug-ins, I scan the registry for installed ActiveX components when the program starts. Create an instance for each ActiveX component and query for a specialized interface called Imyappplugin. If this interface exists, then I think this component is the plugin that my program wants. This does not seem to work, especially if you have more than one ActiveX component installed. Is there a better way to deal with this problem?
Answer:
In this case, Windows does have a better solution: both kinds (category). For developers, the kind is an ActiveX control. Names can be arbitrarily taken, such as "My Acme Plugin" or "Blue insertable thingies". For COM, the kind is just a guid--different kind of catid represents a GUID, which is a bit like a GUID for a class that is called a CLSID.
So how do you use CATID in actual programming? The first is to generate a new GUID (using Guidgen or other similar programs), and we call this newly generated GUID catid_acmeplugin. Then, use a dedicated COM interface icatregister to register your category. The place where this work is done is generally in the DllRegisterServer function. In order to obtain the Icatregister interface, CoCreateInstance or functions that implement the same function must be invoked.
In the DllRegisterServer
CComPtr SPCR;
SPCR. CoCreateInstance (CLSID_StdComponentCategoriesMgr,
NULL, Clsctx_inproc);
This code uses an ATL smart pointer; Ccomptr::cocreateinstance can also be invoked with Icatregister IID:: CoCreateInstance. Once you have the Icatregister, you can call registercategories. The method is to fill in the categoryinfo structure with the information of your own kind first.
CategoryInfo Catinfo;
Catinfo.catid = Catid_acmeplugin;
Catinfo.lcid = 0x0409; Locale=english
Uses_conversion; Uses a2w
wcscpy (Catinfo.szdescription,
A2W ("My Acme Plugin.");
Pcr->registercategories (1, &catinfo);
The next task is how to tell COM that your COM class is Acme Plugin. Icatregister also has a way to do this, it is registerclassimplcategories.
It's in DllRegisterServer, too.
CATID CATID = Catid_acmeplugin;
Pcr->registerclassimplcategories (
Clsid_mypluginobj, 1, &catid);