Главная страница | назад





Article #22268: ATL Templatized QueryInterface Causes Compiler Errors

Question

I'm trying to compile ATL code and the compiler is dying on a QueryInterface call. How do I get rid of this?

Answer

The ATL wants to compile a special templatized version of QueryInterface:

template <class Q>
HRESULT QueryInterface(Q** pp) const
 {
  ATLASSERT(pp != NULL && *pp == NULL);
  return p->QueryInterface(__uuidof(Q), (void**)pp);
 }
This happens because of a conditional statement in one of the ATL header files.

#if (_MSC_VER >= 1100) && defined(__cplusplus) && !defined(CINTERFACE)

In the file unknwn.h. This leads to the pointer you're using (the one that causes this error) having, not the ATL template-wrapper QueryInterface, but the standard one. In order to fix this, simply redefine _MSC_VER in your project conditionals so that the correct behavior is produced.

Last Modified: 20-JUN-00