Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2004

Tip: Looking for answers? Try searching our database.

Pass a C++ COM to another C++ COM  from a C# application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven - 13 Jul 2004 14:35 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.