How do I marshal a stream for COM

2019-07-14 02:57发布

问题:

I am consuming a COM object written in Delphi that requires a Stream.

The interface generated by VS requests a parameter of type "object"

comReader.LoadFromStream(object stream)

When I use a FileStream or MemoryStream I get an "Invalid argument"-exception.

How do I marshal a stream for COM consummation?

回答1:

I think you should create wrapper for .Net Stream that implements COM IStream interface

See this article (There is partly implementation)



回答2:

Edit I found this interesting answer:  How do I declare an IStream in idl so visual studio maps it to s.w.interop.comtypes?

Basically what you want to do is to implement System.Runtime.InteropServices.ComTypes.IStream or use an existing implementing class.

If all else fails You should be able to marshal arbitrary data using UnmanagedMemoryStream. (MSDN page)



标签: c# .net delphi com