getting a com interface from an out of process erver
Hello,
I am creating an instance of an object, then one of the methods of the
object will return an instance to a different object (similar to how the
windows media player com interface works, see
IWMReaderAccelerator::GetCodecInterface for an example).
In process this works fine, but out of process it appears that neither
the IID or the pointer are being marshaled correctly. I did notice that
according to the oleautomation attribute documentation, GUID's are not
one of the types listed as automation compatible (nor are
variants?!?!?). I'd be willing to give up the guid, as long as I could
get the IUnknown ** to work.
I have a sample solution, but the news server won't allow me to attach
it. Key parts of the code follow:
//test code
BOOL CtesterappDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CComPtr<IT1> t1;
CComPtr<IT2> t2;
HRESULT hr;
double x;
hr = t1.CoCreateInstance(__uuidof(T1), 0, CLSCTX_LOCAL_SERVER);
hr = t1->GetTClass(const_cast<GUID *> (&__uuidof(T2)),
reinterpret_cast<IUnknown **> (&t2));
hr = t2->get_somenum(&x);
return TRUE;
}
//idl code
[
object,
uuid(3BB9B8DD-3060-42D3-8F7E-3F1BE464B031),
oleautomation,
dual,
nonextensible,
helpstring("IT1 Interface"),
pointer_default(unique)
]
interface IT1 : IDispatch{
[id(1), helpstring("method GetTClass")] HRESULT GetTClass([in] REFIID
riid, [out] IUnknown** tclass);
};
[
object,
uuid(7A7E3387-8968-4FA1-9481-91D11BEB17EF),
oleautomation,
dual,
nonextensible,
helpstring("IT2 Interface"),
pointer_default(unique)
]
interface IT2 : IDispatch{
[propget, id(1), helpstring("property somenum")] HRESULT
somenum([out, retval] DOUBLE* pVal);
};
//T2::GetTClass
STDMETHODIMP CT1::GetTClass(REFIID riid, IUnknown** tclass)
{
HRESULT hr(S_OK);
if (IsEqualIID(riid, __uuidof(IT2)))
{
hr = CoCreateInstance(__uuidof(T2), NULL, CLSCTX_LOCAL_SERVER,
riid, reinterpret_cast<LPVOID *> (tclass));
}
else
{
hr = E_INVALIDARG;
}
return hr;
}
Thanks,
Drew