managed/unmanaged interfaces

G

Guest

Hi,

I used ATL to create a COM library that does a lot of work via IStreams
that are passed in. I had hoped to test this library using managed C++. I
added my COM library as a reference and vc brought it in and created an
interop dll for me. The problem is that it also wrapped the IStream
interface as a managed interface. I need to use API's such as
SHCreateStreamOnFile in order to get the IStream. This API will not accept
the managed version of the IStream. And I cannot pass the unmanaged version
of the interface into the interop dll. I cannot seem to find any way to get
the unmanaged interface and get an instance of the managed interface from it.
Surely there must be a way to do this, no?
 
G

Guest

Hi,

I don't know if what I have done is "correct", but it seems to work, so
here I'll attempt to answer my own question for the benefit of others (cause
no one has answered yet and I got it working). If any of you pros out there
see my answer and it is not the proper way to go about this then please
correct me.

I created an IStream* and passed it into the necessary API to create the
actual stream. I then did a little dance like this:

//////////////////////////////////////

// get the IUnknown pointer from the stream
CComPtr<IUnknown> pUnk;
pComStream->QueryInterface( &pUnk );

// translate the IStream into the wrapped version
IntPtr p = (int)pUnk.p;
Object* pO =
System::Runtime::InteropServices::Marshal::GetTypedObjectForIUnknown( p,
__typeof(Interop::MyLibrary::IStream) );

pStream = dynamic_cast<Interop::MyLibrary::IStream*>( pO );

//////////////////////////////////////

I was then able to pass the pStream into the wrapped objects from MyLibrary.

I hope this helps somebody out there :blush:)

Manny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top