代码之家  ›  专栏  ›  技术社区  ›  sep

如何列出所有已安装的ActiveX控件?

  •  1
  • sep  · 技术社区  · 14 年前

    我需要显示ActiveX控件列表供用户选择。它需要显示控件名称和描述。

    如何查询已安装控件上的窗口?

    有没有办法区分控制和COM自动化服务器?

    2 回复  |  直到 14 年前
        1
  •  3
  •   In silico    14 年前

    谷歌搜索“枚举ActiveX控件”的结果如下:

    http://www.codeguru.com/cpp/com-tech/activex/controls/article.php/c5527/Listing-All-Registered-ActiveX-Controls.htm

    尽管我会补充说你不需要打电话 AddRef() pCatInfo 自从 CoCreateInstance() 给你打电话。

    我就是这样做的:

    #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;
    }
    
        2
  •  1
  •   Community CDub    7 年前

    出于某种原因,另一个例子为我发布了SEG错误。 这是我的一招:

    https://gist.github.com/810398

    尽管C代码似乎并没有为我列举出所有的代码。 见 how do you enumerate WIN32OLE available servers? 我想,为了得到更多的答案。