c++ How to get a COM object Coclass's progid at runtime

本小妞迷上赌 提交于 2020-01-04 04:40:13

问题


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

Is this possible?

What's the best way to do it?

EDIT: All the coclasses I need to process implement IProvideClassInfo


回答1:


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.

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.

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

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.



来源:https://stackoverflow.com/questions/13362113/c-how-to-get-a-com-object-coclasss-progid-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!