Overview
This code is meant to illustrate how to use COM in order to retrieve a list of all the registered ActiveX controls in your system. The demo application (see screen shot above) displays the names of all located ActiveX controls in a listbox.
Source Code
//Initialise COM libraries
CoInitialize (NULL);
//The Component Category Manager implemented by System implements
//this interface
ICatInformation *pCatInfo=NULL;
//Create an instance of standard Component Category Manager
HRESULT hr=CoCreateInstance (CLSID_StdComponentCategoriesMgr ,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICatInformation ,
(void **)&pCatInfo);
//Increase ref count on interface
pCatInfo->AddRef ();
//IEnumGUID interface provides enumerator for enumerating through
//the collection of COM objects
IEnumGUID *pEnumGUID=NULL;
//We are intersted in finding out only controls so put CATID_Control
//in the array
CATID pcatidImpl[1];
CATID pcatidReqd[1];
pcatidImpl[0]=CATID_Control;
//Now enumerate the classes i.e. COM objects of this type.
pCatInfo->EnumClassesOfCategories (1,
pcatidImpl,
0,
pcatidReqd ,
&pEnumGUID);
//Enumerate as long as you get S_OK
CLSID clsid;
while( (hr= pEnumGUID->Next( 1, &clsid, NULL ))==S_OK )
{
BSTR bstrClassName; //Get the information of class
//This is what MSDN says about the parameters
/*-----------------------------------------------
USERCLASSTYPE_FULL The full type name of the class.
USERCLASSTYPE_SHORT A short name (maximum of 15 characters) that
is used for popup menus and the Links dialog
box.
USERCLASSTYPE_APPNAME The name of the application servicing the class
and is used in the Result text in dialog boxes.
-----------------------------------------------*/
OleRegGetUserType (clsid,USERCLASSTYPE_FULL,&bstrClassName);
CString strControlName(bstrClassName);
//Add string in our listbox
m_list1.AddString (strControlName);
}
//we are done so now release the interface ptr
pCatInfo->Release ();
CoUninitialize ();
The program first intialises the COM libraries. Then it creates an instance of standard component category manager
HRESULT hr=CoCreateInstance(CLSID_StdComponentCategoriesMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICatInformation,
(void **)&pCatInfo);
IcatInformation interface provides the information about COM classes and categories. IEnumGUID interface provides enumerator for iterating through the collection of COM classes. Then we enumerate the controls with a call to EnumClassesOfCategories.As we are interested in only controls We fill the array with CATID_Control.Next we enumerate through the collection ,get the class name And put it in the listbox.
ActiveX
При нажатии на кнопку, надо вывести в список все зарегистрированные на компьютере ActiveX. После выбора из списка выбранный ActiveX должен загружаться на форму и в соседних списках должны быть автоматически загружены его свойства и методы. Выбрав метод из списка и задав параметры для него пользователь при желании может выполнит его.
Если можно расскажите по подробней шаги реализации такой программы.
Спасибо.
P.S.
Я посмотрела в реестре раздел CLSID, но как вытащить названия не знаю. Вот в Builder если нажать меню Project далее Import Type Library, то получаем окно со списком ActiveX (см.рисунок). Как построить такой список?
Только надо было добавить две дериктивы для Builder 6:
#include "objbase.h"
#include "comcat.h"
Подскажите, как можно загрузить в отдельный список методы объекта ActiveX загруженного в OleConteiner? :confused: