Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

c++ - How to list all installed ActiveX controls?

I need to display a list of ActiveX controls for the user to choose. It needs to show the control name and description.

How do I query Windows on the installed controls?

Is there a way to differentiate controls from COM automation servers?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...