0

i need to inherit an interface with abstract methods , in VB/c# we simply override methods from our interface while there is no need to code for IUnknown or IDispatch methods

but in c++, after inheriting interface in class & overriding methods in interface, when i tried to instantiate derived class i am getting following error

error C2259: 'Imyinterface' : cannot instantiate abstract class
1>          due to following members:



'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
'ULONG IUnknown::AddRef(void)' : is abstract
 'ULONG IUnknown::Release(void)' : is abstract 

so i need to override/define IUnknown and IDispatch methods e.g. addref,Release,QueryInterface,invoke,gettypeinfo

as they appears to be standard functions ,where can i get their code/definitions e.g.ATL or or any typelib? or any references where i can get code/examples of above methods

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
user1176743
  • 5
  • 1
  • 4

2 Answers2

0

QueryInterface: If the interface identified by the GUID that is passed in can be reached, put a pointer to the interface in the void ** parameter; else set the void ** to NULL. Return the appropriate HRESULT.

AddRef: Increase the reference count of the interface.

Release: Decrease the reference count of the interface.

I would suggest getting a good book on COM before delving into this. Used copies of Inside Com (Microsoft Programming Series) by Dale Rogerson are cheap. It does have examples. Read the reviews on Amazon to find out whether you'd like to buy this book or not.

Lumi
  • 14,775
  • 8
  • 59
  • 92
  • thank you,for book reference ,does it have code or examples?, because i have been through couple of books which explains mechanism but don't have solid code/examples. – user1176743 May 26 '12 at 07:33
-1

You need to override those methods and provide their definitions(in your derived class) and for all the functions declared pure virtual in your base class.
Unless you do so your derived class also acts as an abstract class and you cannot create any objects of it.

For the second Q, no I don't have any real good idea for what standard implementations of those methods should do.

Alok Save
  • 202,538
  • 53
  • 430
  • 533