How to list all installed ActiveX controls?

后端 未结 2 1040
你的背包
你的背包 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条回答
  •  萌比男神i
    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 
    #include 
    #include 
    
    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;
    }
    

提交回复
热议问题