ATL: creating object fails

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Joe (joerider_at_uboot.com)
Date: 02/17/05


Date: Thu, 17 Feb 2005 11:42:57 +0100

Hello!

My program
interface Itest : IDispatch
{
   [id(2), helpstring("Methode getTest")] HRESULT getTest([out,retval]
      Itest* *t);
};

STDMETHODIMP Ctest::getTest(Itest* *t)
{
   Ctest x; //doesn't work
   *t=this; //works
   *t = x;
   return S_OK;
}

Compiler quits with this messages:
//Sorry the messages are translated from german
test.cpp(30) : error C2259: "Ctest" : Instance from abstract class
cannot be created because of following elements:
test.h(10) : See declaration of 'Ctest'
test.cpp(30) : warning C4259: 'long __stdcall
Ctest::QueryInterface(const struct _GUID &,void ** )' : Virtual function
was not defined
test.h(27) : See declaration of 'QueryInterface'

That means, that QueryInterface should be implemented. Why was there no
need to implement this function for returning this. What constructor was
called for getting "this"? Or better: what class is "this" of?

Is there a possibility to create an object the same way as "this" is
created, without implementing this function (QueryInterface)? I've no
idea how this function should be implemented.

Thanks, Joe