IUnknown is the root interface
for all COM
objects. Since COM
objects are, at bare minimum, just reference counted
C++ classes, the only functionality IUnknown gaurantees is reference counting. To gaurantee correct functionality, IUnknown methods are always the first entries in the VTable
Methods of IUnknown:
(in vtable order)
returns a pointer
to a specified interface on an object to which a client currently holds an interface pointer. When the call to QueryInterface succeeds, the implementation should call AddRef automatically.
increments the reference count for an interface on an object. Call this function for every new copy of an interface pointer that you make. If you are passing a copy of a pointer back from a function, you must call AddRef on that pointer. You must also call AddRef on a pointer before passing it as an in-out parameter
to a function; the function will call Release before copying the out-value on top of it.
decrements the reference count for an interface on an object. Once the reference count on an object falls to 0, the implementation must free the object. If you are writing a function that takes an in-out parameter, call Release on the pointer you are passing in before copying the out-value on top of it.