Brief discussion on COM plug-in model

Source: Internet
Author: User
Tags knowledge base

First, on the implementation of the common DLL plug-in VC Knowledge Base has been an article introduced, but in many large software (such as ArcGIS, Office) is not the use of this method, based on COM plug-ins in today's large software applications more extensive.

Second, the realization of plug-ins inseparable from three elements

Plug-in manager (that is, the master to use these plug-ins)

Plug-in basic interface (ie: Plug-ins and managers are recognized interface standards), in the DLL plug-in this element is usually a standard C + + header file, in the COM plug-in we often have a base class interface com, in this COM it only defines the interface, do not make any implementation.

Plug-in com, in these COM, they only implement the base class COM library interface, do not have their own interface.

In the example of this article TestSvr is the first element, is the plug-in manager, the plugin directory of the two projects is the third element is the plug-in com,interface code directory under the project is to provide the basic class of COM, is the second element we mentioned above.

Third, in the DLL plug-in we search the plug-in method is to store the plugin in the main program with a relatively fixed directory, the main program to search the directory file and search for plug-ins, in the COM plug-in we can not use this method to search Plug-ins, here we use the method is every COM plug-ins are injected into a fixed COM group, The main program searches for a plug-in in a COM group.

The following code is to register and reverse a COM to a COM group:

void Specialreg (GUID id_subitem,bool bregister)
{
icatregister* picatregister = NULL;
HRESULT hr =:: CoCreateInstance (CLSID_StdComponentCategoriesMgr,
Null
Clsctx_all,
Iid_icatregister,
(void**) &picatregister);
if (FAILED (HR))
{
ErrorMessage ("Could not create" comcat component. ", HR);
return;
}
CategoryInfo Catinfo;
Catinfo.catid = catid_mycategory;
Catinfo.lcid = Locale_system_default;
wcscpy (Catinfo.szdescription,scategoryname);
if (bregister)
{
hr = picatregister->registercategories (1, &catinfo);
hr = Picatregister->registerclassimplcategories (Id_subitem,
1,
&catid_mycategory);
}
Else
{
hr = Picatregister->unregisterclassimplcategories (Id_subitem,
1,
&catid_mycategory);
icatinformation* picatinformation = NULL;
hr = Picatregister->queryinterface (iid_icatinformation,
(void**) &picatinformation);
ienumclsid* pienumclsid = NULL;
hr = picatinformation->enumclassesofcategories (1,
&catid_mycategory,
0,
Null
&PIENUMCLSID);
CLSID clsid;
hr = Pienumclsid->next (1, &clsid, NULL);
if (hr = = S_FALSE)
{
hr = picatregister->unregistercategories (1, &catid_mycategory);
}
Pienumclsid->release ();
Picatinformation->release ();
}
if (Picatregister)
{
Picatregister->release ();
}
}

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.