views:

43

answers:

2

How to create a method in COM that returns a pointer to an interface, this needs to be done inside the IDL file.

EDIT:

How do I implement this within a class:

STDMETHODIMP CBlah::get_Something(IOtherBlah** retval){
return m_protectedvar->QueryInterface(retval);
}
STDMETHODIMP CBlah::put_Somthing(IOtherBlah* rhs){
m_protectedvar = rhs;
return S_OK;
}

The above is not working. I'm getting the following error:

cannot instantiate abstract class with[ Base=Blah ] due to following members:
'HRESULT IBlah::putref_Something(IOtherBlah*)' : is abstract
+5  A: 

Something like this:

 interface IYourInterface {
     HRESULT GetPointer( [out, retval]IInterface** );
 };

The caller will call it like this:

 IInterface* pointer = 0;
 HRESULT hr = yourInterfacePointer->GetPointer( &pointer );
sharptooth
trying to do a get/set methods, one to set the object and one to get the pointer to the object/interface
Phill Pafford
No problem, use the snippet by user nobugz in the other answer.
sharptooth
Thanks for the help in the right direction
Phill Pafford
I'm getting an error, please see edit
Phill Pafford
+2  A: 
[ attributes here...]
interface IBlah : IDispatch {
  [id(1), propget]    HRESULT Something([out,retval] IOtherBlah** retval);
  [id(1), propputref] HRESULT Something([in] IOtherBlah* rhs);
};
Hans Passant
Thanks for the help in the right direction
Phill Pafford
@Phill - why did you unmark the answer? What else do you need?
Hans Passant
I'm getting an error, please see edit
Phill Pafford
You have to write putref_Something(), not put_Somthing().
Hans Passant
It lives :) Thanx man, Cheers!!!
Phill Pafford