简体   繁体   English

如何枚举实现特定COM接口的所有coclass?

[英]How To Enumerate All coclasses That Implement A Particular COM Interface?

I will describe the problem as simple as i can; 我将尽可能简单地描述问题;

Let's say we have a com client that defines several interfaces. 假设我们有一个定义了几个接口的com客户端。

In order to improve our com client's functionality; 为了改善我们的com客户端的功能; several, independent companies develops & deploys com servers that implements the interface. 几家独立公司开发和部署实现该接口的com服务器。 It is possible that the target machine may have com servers that implements the same interface. 目标计算机可能具有实现相同接口的com服务器。

Now here is the problem; 现在问题在于此;

Our com client have no idea about the com servers on the target machine because they will have been developed independently. 我们的com客户端不知道目标机器上的com服务器,因为它们是独立开发的。 But still, we can ask independent companies to follow a specific installation procedure. 但是,我们仍然可以要求独立公司遵循特定的安装程序。

Now here is the question; 现在问题是这样的;

What kind of technique should we use to find out all the compatible com servers that is deployed on the target machine and then instantiate required objects? 我们应该使用什么样的技术来找出部署在目标机器上的所有兼容的com服务器,然后实例化所需的对象?

There's no standard COM cataloging service that I know of, although COM+ might have something. 我知道没有标准的COM编目服务,尽管COM +可能有一些东西。 Take a look at HKCR\\Component Categories , you'll find GUIDs of type of components. 看看HKCR\\Component Categories ,你会发现组件类型的GUID。 Like 0DE86A57-2BAA-11CF-A229-00AA003D7352, described as "Class implements IPersistPropertyBag". 与0DE86A57-2BAA-11CF-A229-00AA003D7352类似,描述为“Class implements IPersistPropertyBag”。 A coclass declares this same guid in its CLSID\\{guid}\\Implemented Categories . 一个coclass在其CLSID\\{guid}\\Implemented Categories声明了这个相同的guid。 This seems like a good match for your scenario. 这似乎是您的场景的一个很好的匹配。

You would have to pick a guid and tell the component authors about it. 你必须选择一个guid并告诉组件作者。 They have to write the Implemented Categories key with their installer. 他们必须使用安装程序编写Implemented Categories键。

It is still a fairly awkward slog through the CLSID keys, you don't want to do this very often. 通过CLSID键仍然是一个相当尴尬的困难,你不想经常这样做。 But at least you won't have to load DLLs to discover interfaces, that could have all kinds of nasty side-effects. 但至少你不必加载DLL来发现接口,这可能会产生各种令人讨厌的副作用。 I'd recommend a dialog in your Options menu that lets the user start a scan and choose, also a good way to disable misbehaving components. 我建议在“选项”菜单中选择一个对话框,让用户开始扫描并选择,这也是禁用行为不当组件的好方法。

Btw, the support pain that this can cause usually makes apps work from an 'approved' list. 顺便说一下,这可能导致的支持性疼痛通常会使应用程序在“已批准”列表中运行。

Hans had a great idea. 汉斯有个好主意。

I haven't used the Component Categories before, but I suggest you avoid touching the registry directly since MS provides APIs to access the Component Categories. 我之前没有使用过组件类别,但我建议您不要直接触摸注册表,因为MS提供了访问组件类别的API。 Check this out: 看一下这个:

http://msdn.microsoft.com/en-us/library/ms692551(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ms692551(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM