Understand the concept of "kind" (Category) in COM programming

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.