In COM, if I have an interface IBase and an interface IX which inherits from IBase, can I call methods of IBase through an IX pointer, and if not, why can I call Release() and AddRef() on any COM interface pointer without an upcast?
+4
A:
Yes, you can call whatever method of the base through the pointer to the derived. That's exactly why you can call AddRef()
, Release()
and QueryInterface()
through any interface pointer.
sharptooth
2009-10-23 09:07:32
Cool... thanks. I hoped that was the case. I'm pretty new to COM, though I've been aware of its basics for a while, but I'm rewriting somebody's DirectShow code and they use QI for exactly that case all over the place, so it got me worried!
Jesse Pepper
2009-10-23 09:15:18
They could confuse the upcast with the downcast. Downcast requires a QI() call (and a check to see if it succeeded).
sharptooth
2009-10-23 09:20:45