How to list all installed ActiveX controls?

后端 未结 2 1037
你的背包
你的背包 2020-12-21 19:50

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 cont

相关标签:
2条回答
  • 2020-12-21 20:41

    for some reason the other example posted seg faults for me. Here's my stab at it:

    https://gist.github.com/810398

    Though that C code doesn't seem to enumerate all of them for me. See how do you enumerate WIN32OLE available servers? for more answers, I think.

    0 讨论(0)
  • 2020-12-21 20:42

    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\n", name);
            // Release string.
            ::SysFreeString(name);
        }
    
        // Clean up.
        enumGuid->Release();
        catInfo->Release();
        ::CoUninitialize();
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题