A: 

Did you define the body of CTest::QueryInterface() in the header file rather than in the .cpp file? If so you may get this error.

polyglot
A: 

The problem is you are not linking properly to the ATL lib files. Check your project options in Visual Studio and make sure you are statically linking to ATL.

JaredPar
polyglot
+1  A: 

Thanks for the answers, but the issue in the end seems to of been that I was trying to QueryInterface from the constructor. Once I moved it to a separate method everything worked fine.

Does anyone have any docs on why you cannot call QueryInterface from a constructor?

Zenox
Have you looked at this MSDN article?http://support.microsoft.com/kb/241852
polyglot
Regardless of whether you *can* call QueryInterface, it's a virtual function, so the standard advice *against* calling virtual methods from constructors applies.
Rob Kennedy
QueryInterface (aka QI) is generally not called from constructors because it relies on the object having been fully constructed to work. Objects are constructed from the base class out, and if the COM support is added on as a wrapper around a base class, QI will never work from any constructor along the inheritance chain.So this stuff is usually done in a FinalConstruct or an Initialize method.
Drew Hoskins
Thank you for the answers guys. These were great explinations.
Zenox