Wednesday, June 20, 2007

Listing All Registered ActiveXControls / COM object based on there category

//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 ,
IID_ICatInformation ,
(void **)&pCatInfo);

//Increase ref count on interface
pCatInfo->AddRef ();

//IEnumGUID interface provides enumerator for enumerating through
//the collection of COM objects

//We are intersted in finding out only controls so put CATID_Control
//in the array
CATID pcatidImpl[1];
CATID pcatidReqd[1];
// Want only my Plugin Category

// Want all Active X Control

//Now enumerate the classes i.e. COM objects of this type.
pCatInfo->EnumClassesOfCategories (1,
pcatidReqd ,

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

No comments: