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

1

4

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

Paraesthesia answered 13/11, 2012 at 14:3 Comment(2)
maybe this is useful: #1272561Cruiser
Thanks, but I didn't find my answer, it's related to c#/.NETParaesthesia
T
6

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.

Tache answered 13/11, 2012 at 14:32 Comment(1)
Very complete answer! All the objects I needed to process implemented IProvideClassInfo so I used this option to get the CLSIDParaesthesia

© 2022 - 2024 — McMap. All rights reserved.