Having pointer to COM interface that are implemented by some concrete component class object is it possible to get a GUID of the underlying object that implements this interface (CLSID)?
Update 1
More generally, I have a function like SetFont(ICanvasFont* font)
and I need a way to determine if the underlying object that implements the ICanvasFont
interface is of a certain class (say MCanvasFont
).
IUnknown::QueryInterface
on this interface pointer to obtain one of the following:IPersist
,IPersistStream
,IPersistStreamInit
or otherIPersist*
interfaces. If you are lucky to get one, thenGetClassID
method will get you theCLSID
class identifier (alternate option isIProvideClassInfo
andIProvideClassInfo::GetClassInfo
).Note that this kind of information does not have to exist. An interface pointer can be valid without having
CLSID
on the class implementing it.UPD. If the main goal is to recognize your own implementation on the provided interface ("Is the provided
ICanvasFont
the instance of my ownMCanvasFont
class, or it is something different?"), then the easiest yet efficient way is to implement some extra private interface on the class. If your querying it succeeds, then you recognize the instance. Provided no marshaling takes place, you can possibly evenstatic_cast
back to original C++ pointer.