Re: AddRef/Release debugging
Jason S <jmsachs@gmail.com> wrote:
If I'm using ATL objects deriving from CComObjectRootEx<> and
CComCoClass<>, what's a good way to write debug hooks into Addref/
Release, to allow me to put a breakpoint that triggers on changes in
reference count for a *specific* class?
Would this work?
class ATL_NO_VTABLE Cblah :
public CComObjectRootEx<CComSingleThreadModel>,
{
typedef CComCoClass<Cblah, &CLSID_blah> coclass_base_t;
STDMETHOD_(ULONG, AddRef)() {return coclass_base_t::AddRef(); }
STDMETHOD_(ULONG, Release)() { return coclass_base_t::Release(); }
...
}
No, it wouldn't work. AddRef and Release are implemented by a class
derived from yours (e.g. CComObject), so your override would never be
called. Besides, CComCoClass does not have AddRef and Release methods,
so the code you show shouldn't even compile.
If for some reason you are not happy with _ATL_DEBUG_QI and
_ATL_DEBUG_INTERFACES macros, you need to override InternalAddRef and
InternalRelease:
class ATL_NO_VTABLE Cblah :
public CComObjectRootEx<CComSingleThreadModel>,
...
{
typedef CComObjectRootEx<CComSingleThreadModel> BaseClass;
ULONG InternalAddRef() {return BaseClass::InternalAddRef();}
ULONG InternalRelease() {return BaseClass::InternalRelease();}
};
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925