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::QueryInterfaceon this interface pointer to obtain one of the following:IPersist,IPersistStream,IPersistStreamInitor otherIPersist*interfaces. If you are lucky to get one, thenGetClassIDmethod will get you theCLSIDclass identifier (alternate option isIProvideClassInfoandIProvideClassInfo::GetClassInfo).Note that this kind of information does not have to exist. An interface pointer can be valid without having
CLSIDon the class implementing it.UPD. If the main goal is to recognize your own implementation on the provided interface (“Is the provided
ICanvasFontthe instance of my ownMCanvasFontclass, 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_castback to original C++ pointer.