ATL Templatized QueryInterface Causes Compiler Errors

By: mykle hoban

Abstract: This document describes how to remove the compiler errors that will occaisionally happen when using the ATL in C++Builder


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


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.

Server Response from: ETNASC03