Search code examples
c++com

Is there a way to query the current reference count of a _com_ptr_t object?


I'm having some issues (crashing) with a COM object that is wrapped in a _com_ptr_t template object. I need to interrogate the object to see what the reference count is, because I'm pretty sure that the object is getting destroyed prematurely.

It would be even better if I could somehow hook into the AddRef() and Release() functions, but I can't seem to find where these are beyond the ones located in the _com_ptr_t class. Ideas?


Solution

  • _com_ptr_t wraps an IUnknown instance, but hides the return of AddRef and Release which would be the current reference count. GetInterfacePtr should "lift the fog".