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

2 Answers 2

5

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 );
Sign up to request clarification or add additional context in comments.

2 Comments

trying to do a get/set methods, one to set the object and one to get the pointer to the object/interface
No problem, use the snippet by user nobugz in the other answer.
2
[ attributes here...]
interface IBlah : IDispatch {
  [id(1), propget]    HRESULT Something([out,retval] IOtherBlah** retval);
  [id(1), propputref] HRESULT Something([in] IOtherBlah* rhs);
};

2 Comments

@Phill - why did you unmark the answer? What else do you need?
You have to write putref_Something(), not put_Somthing().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.