Re: ATL com server can pass interface as parameters?
On 4=A4=EB19=A4=E9, =A4W=A4=C81=AE=C918=A4=C0, "Igor Tandetnik" <itandet...=
@mvps.org> wrote:
ceasar...@gmail.com wrote:
Server side
========
class CMy2 : IMy2
{
// IUnknown
HRESULT STDMETHODCALLTYPE QueryInterface(const IID& iid, void**
ppv) { return S_OK; }
You never set *ppv to anything, and yet you return S_OK. After the call
to QueryInterface, the client would try to use the value in *ppv (that's
why they called QI in the first place, after all), and would crash.
Hi Igor,
I try to modify CMy2::QueryInterface API on server side:
HRESULT STDMETHODCALLTYPE CMy2::QueryInterface(const IID &iid, void
**ppv)
{
if ((iid == IID_IUnknown) || (iid == IID_IMy2))
{
*ppv = static_cast<IMy2 *>(this);
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
And server will get the response calls after client calls - hr =
pIMy1->GetInterface(&pIMy2);
Server side:
QueryInterface({IID_IMarshal})
| return E_NOINTERFACE;
QueryInterface(IID_IMarshal)
| return E_NOINTERFACE;
QueryInterface({0000001B-0000-0000-C000-000000000046}) |
return E_NOINTERFACE;
QueryInterface({IID_IUnknown})
| return static_cast<IUnknown *>(this);
QueryInterface({IID_IStdMarshalInfo})
| return E_NOINTERFACE;
QueryInterface({IID_IExternalConnection})
| return E_NOINTERFACE;
QueryInterface({4C1E39E1-E3E3-4296-AA86-EC938D896E92}) | return
E_NOINTERFACE;
QueryInterface({IMy2})
| return static_cast<IMy2 *>(this);
Unhandled exception in ComServer.exe(OLE32.DLL):0xC0000005 Access
Violation
It leads to crash due to OLE32.dll access violation.
Am I wrong?
How can I resolve this issue?
Thank for your help in advance.
Ceasar