Re: Interface method vs QueryInterface()
On Jan 2, 5:16 pm, "Alexander Nickolov" <agnicko...@mvps.org> wrote:
It helps if you know how the proxy is organized. All
interfaces except for IUnknown are implemented in
so called stublets loaded by the proxy manager. When
you set an interface blanket, you only do it on the stublet.
What happens when i set blanket for IUnknown which is not in stublet?
IUnknown is the only interface implemented on the
proxy manager itself. Thus a blanket for any other
interface does not apply to it. E.g. calling IUnknown
methods through any interface uses the blanket you set
for IUnknown and not the blanket for that interface (if
it calls the object's IUnknown instead of resolving it
at the proxy manager of course). Is that clearer now?
In practical terms, you need to QI for IUnknown (which
does not incur an IUnknown call to the object) and set
a blanket before you can QI for any other interface on
the object.
Now it is clearer. Thanks.
In the connection point scenario, server will call back code resided in
client side. In the following example code (extracted from AtlAdvise),
I have to set proxy blanket for every level of interfaces to fulfill
the advise.
BOOL
CSecuTestClientDlg::AdviseEventSink()
{
if (m_bSinkAdvised)
return TRUE;
IUnknown* pUnk = NULL;
CComPtr<IUnknown> spUnk = (*m_pTestCP); // m_pTestCP was got by
CoCreateInstanceEx
pUnk = spUnk.p;
checkBlanketInfo();
CComPtr<IUnknown> pTestCPUnk;
HRESULT hr = (*m_pTestCP)->QueryInterface(IID_IUnknown,
(void**)&pTestCPUnk);
_setProxyBlanketFor( pTestCPUnk.p ); // set proxy blanket
CComPtr<IConnectionPointContainer> pCPC;
CComPtr<IConnectionPoint> pCP;
hr = pTestCPUnk->QueryInterface(IID_IConnectionPointContainer,
(void**)&pCPC);
if (SUCCEEDED(hr))
{
_setProxyBlanketFor( pCPC.p ); // set proxy blanket
hr = pCPC->FindConnectionPoint(DIID__ITestCPEvents, &pCP);
}
if (SUCCEEDED(hr))
{
_setProxyBlanketFor( pCP.p ); // set proxy blanket
hr = pCP->Advise(m_pTestCPEventsUnk, &m_dwCookie); //
server will callback client
}
return SUCCEEDED(hr);
}
Is this the right way?