views:

18

answers:

1

In ATL there's a BEGIN_COM_MAP macro for declaring a table that controls how the QueryInterface() behaves when called on the corresponding class object.

Inside it has the following line:

    static const _ATL_INTMAP_ENTRY _entries[] = { DEBUG_QI_ENTRY(x)

which means that the first table entry will be DEBUG_QI_ENTRY which expands as following:

#ifdef _ATL_DEBUG
#define DEBUG_QI_ENTRY(x) \
     {NULL, \
     (DWORD_PTR)_T(#x), \
     (ATL::_ATL_CREATORARGFUNC*)0},
#else
#define DEBUG_QI_ENTRY(x)
#endif //_ATL_DEBUG

which effective leads to every class having this entry when _ATL_DEBUG is defined. But in CComObjectRootBase::InternalQueryInterface() there's an assertion:

// First entry in the com map should be a simple map entry
//ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY);

which fails for just every class when compiled with _ATL_DEBUG because it expects the pFunc to be _ATL_SIMPLEMAPENTRY (which is 1) but instead finds 0 put there by DEBUG_QI_ENTRY().

What's the sense in DEBUG_QI_ENTRY() and how do I use the COM map macros to avoid the described problem?

+1  A: 

_ATL_DEBUG doesn't seem to be documented, so I wonder if it's just a hook to debug QueryInterface calls -- if the assertion fails, you break into the debugger and can inspect the interface map, call stack, etc.

Or maybe it's some left-over.

Kim Gräsman