PInvoke和IStream [英] PInvoke and IStream
问题描述
我有一个用c ++编写的dll导出的函数,其签名如下:
Foo( LPSTREAM *pStream, UINT &Size )
返回内存流及其大小.我遇到的困难是为导出的函数创建签名,然后尝试在C#中读取流.曾经能够使用不安全的"字节指针来获取信息,但这不符合我们的要求.
任何想法,示例,示例等,将不胜感激.
您可以这样做:
[DLLImport(@"mydll.dll")]
public static extern void Foo(out ComTypes.IStream Stream, ref uint Size);
这样称呼:
ComTypes.IStream Stream = null;
uint Size;
Foo(out Stream, ref Size);
通常,请确保您的调用约定匹配(C#默认为stdcall,C ++默认为cdecl).
顺便说一句,为什么IStream
知道它的大小并告诉您是否要发送它,为什么又将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?
这篇关于PInvoke和IStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!