开发者

PInvoke and IStream

开发者 https://www.devze.com 2023-03-13 01:10 出处:网络
I have an exported function from a dll written in c++ with the following signiture: Foo( LPSTREAM *pStream, UINT &Size )

I have an exported function from a dll written in c++ with the following signiture:

Foo( LPSTREAM *pStream, UINT &Size ) 

that returns an memory stream and obviously its size. What I am having difficulties with is creating a signiture for the exported function and then attempting to read the stream in C#. At one point was able to开发者_运维知识库 use "unsafe" byte pointer to get the information, but this does not fit our requirements.

Any thoughts, examples, samples etc would be greatly appreciated.


You can do this like so:

[DLLImport(@"mydll.dll")]
public static extern void Foo(out ComTypes.IStream Stream, ref uint Size);

Call it like this:

ComTypes.IStream Stream = null;
uint Size;
Foo(out Stream, ref Size);

As normal, make sure your calling conventions match (C# defaults to stdcall, C++ defaults to cdecl).


As an aside, why return the Size separate from the stream since IStream knows its size and will tell you if you ask it to?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号