Hello,
I have a C# application which creates two C++ COMs, and then pass
one to another. the code snippet as follows:
COM1 and COM2 are two COMs implemented in ATL.
in C#:
COM1.CCOM1Class com1 = new COM1.CCOM1Class ();
COM2.CCOM2Class com2 = new COM2.CCOM2Class ();
... ...
(1) com1.SetCOM2(com2);
......
The prototype of SetCOM2 in COM1.CCOM1Class com1 is:
[id(1), helpstring("method SetCOM2 ")] HRESULT SetCOM2 ([in]
IDispatch* pICOM2);
in its definition:
STDMETHODIMP CCOM1Class ::SetCOM2 (IDispatch* pICOM2)
{
HRESULT hr = S_OK;
try
{
COM2::ICOM2Ptr ptr;
(2) hr = pICOM2->QueryInterface(COM2::IID_ICOM2, (void**)&ptr);
if(ptr == NULL) //Test only
{
}
}
catch(...)
{
ATLASSERT(FALSE);
}
return hr;
}
The code was compiled, but when was executed, at point (2), return hr
indicated the Empty pointer. I think the point (1) may be not correct,
but I don't know how to fix it.
Please help or point to related docs.
Thanks in advance.
Steven Wang
Bob Rundle - 14 Jul 2004 18:23 GMT
I've had a problem similar to yours, however its not clear that yours is of
the same time.
When you access a COM pointer in the runtime, a RCW is constructed. When
you pass the RCW to unmanaged code you would expect the COM pointer to be
simply unwrapped. However this is not what I think happens. What I believe
happens is that the RCW is wrapped again with a CCW and this is passed to
unmanaged code.
Everything will work fine, until the managed RCW is disposed. Then the
access to the COM pointer through the CCW will fail. The way I solved my
problem was to access the raw COM pointer in managed code and pass it to the
second COM interface as Int32.
Hope this helps,
Bob Rundle
> Hello,
>
[quoted text clipped - 44 lines]
>
> Steven Wang