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