如何获取COM对象Coclass的progid在运行时

如何获取COM对象Coclass的progid在运行时

本文介绍了c ++如何获取COM对象Coclass的progid在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个函数来动态地从COM对象中提取progid。

I need to write a function that dynamically extracts the progid from a COM object.

这是否可能?

这是最好的方法是什么?

What's the best way to do it?

编辑:我需要处理的所有coclass实现IProvideClassInfo

All the coclasses I need to process implement IProvideClassInfo

推荐答案

首先,不能保证信息在第一位。

First of all, there is no guarantee the information is available in first place. Even if you just instantiated an object using ProgID, you might be unale to get it back.

最简单的是查询 IPersist

The easiest is to query one of IPersist and friends (IPersistStream etc.) interfaces, and call IPersist::GetClassID to obtain CLSID. Then convert to ProgID using ProgIDFromCLSID or via registry lookup.

另一个选择是查询 IProvideClassInfo IProvideClassInfo2 以此备用方式访问感兴趣的CLSID。

Another option is to query IProvideClassInfo and IProvideClassInfo2 to access the CLSID of interest in this alternate way.

第三个选项,如果两个上面工作,是查询 IDispatch 并尝试打开类型库,然后通过查找coclass信息进行迭代。

The third option, if none of the two above worked, is to query IDispatch and attempt to open type library, then iterate through looking up for coclass information.

这篇关于c ++如何获取COM对象Coclass的progid在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:48