How do I marshal a stream for COM

2019-07-14 02:30发布

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?

标签: c# .net delphi com
2条回答
Anthone
2楼-- · 2019-07-14 03:06

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)

查看更多
够拽才男人
3楼-- · 2019-07-14 03:29

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

See this article (There is partly implementation)

查看更多
登录 后发表回答