如何在COM中创建一个返回指向接口的指针的方法,这需要在IDL文件中完成。
编辑:
我如何在一个类中实现它:
STDMETHODIMP CBlah::get_Something(IOtherBlah** retval){
return m_protectedvar->QueryInterface(retval);
}
STDMETHODIMP CBlah::put_Somthing(IOtherBlah* rhs){
m_protectedvar = rhs;
return S_OK;
}
以上不起作用。我收到以下错误:
cannot instantiate abstract class with[ Base=Blah ] due to following members:
'HRESULT IBlah::putref_Something(IOtherBlah*)' : is abstract
答案 0 :(得分:5)
这样的事情:
interface IYourInterface {
HRESULT GetPointer( [out, retval]IInterface** );
};
来电者会这样称呼它:
IInterface* pointer = 0;
HRESULT hr = yourInterfacePointer->GetPointer( &pointer );
答案 1 :(得分:2)
[ attributes here...]
interface IBlah : IDispatch {
[id(1), propget] HRESULT Something([out,retval] IOtherBlah** retval);
[id(1), propputref] HRESULT Something([in] IOtherBlah* rhs);
};