简体   繁体   中英

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.

In order to improve our com client's functionality; several, independent companies develops & deploys com servers that implements the interface. It is possible that the target machine may have com servers that implements the same interface.

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. 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?

There's no standard COM cataloging service that I know of, although COM+ might have something. Take a look at HKCR\\Component Categories , you'll find GUIDs of type of components. Like 0DE86A57-2BAA-11CF-A229-00AA003D7352, described as "Class implements IPersistPropertyBag". A coclass declares this same guid in its CLSID\\{guid}\\Implemented Categories . This seems like a good match for your scenario.

You would have to pick a guid and tell the component authors about it. They have to write the Implemented Categories key with their installer.

It is still a fairly awkward slog through the CLSID keys, you don't want to do this very often. But at least you won't have to load DLLs to discover interfaces, that could have all kinds of nasty side-effects. 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. Check this out:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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