Googling for "enumerate activex controls" give this as the first result:
http://www.codeguru.com/cpp/com-tech/activex/controls/article.php/c5527/Listing-All-Registered-ActiveX-Controls.htm
Although I would add that you don't need to call AddRef()
on pCatInfo
since CoCreateInstance()
calls that for you.
This is how I would do it:
#include <cstdio>
#include <windows.h>
#include <comcat.h>
int main()
{
// Initialize COM
::CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Obtain interface for enumeration
ICatInformation* catInfo = NULL;
HRESULT hr = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr,
NULL, CLSCTX_INPROC_SERVER, IID_ICatInformation, (void**)&catInfo);
// Obtain an enumerator for classes in the CATID_Control category.
IEnumGUID* enumGuid = NULL;
CATID catidImpl = CATID_Control;
CATID catidReqd = CATID_Control;
catInfo->EnumClassesOfCategories(1, &catidImpl, 0, &catidReqd, &enumGuid);
// Enumerate through the CLSIDs until there is no more.
CLSID clsid;
while((hr = enumGuid->Next(1, &clsid, NULL)) == S_OK)
{
BSTR name;
// Obtain full name
::OleRegGetUserType(clsid, USERCLASSTYPE_FULL, &name);
// Do something with the string
printf("%S
", name);
// Release string.
::SysFreeString(name);
}
// Clean up.
enumGuid->Release();
catInfo->Release();
::CoUninitialize();
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…