How do I marshal a stream for COM

瘦欲@ 提交于 2020-01-15 08:31:34

问题


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)



来源:https://stackoverflow.com/questions/7849722/how-do-i-marshal-a-stream-for-com

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!