PInvoke and IStream
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?
精彩评论