在调用“ref byte []”时设置IDispatch :: Invoke的参数 [英] Setting up parameter for IDispatch::Invoke when calling "ref byte []"
问题描述
这是一个互操作性的问题,所以我想我会问那些比我更聪明的人(所以,大多数人都是......)
我有一些C#代码,包含在COM中:
This is a bit of an interop question, so I thought I'd ask those wiser than me (so, that's most of you...)
I have a bit of C# code, wrapped up in COM:
namespace Blah
{
public interface Blether
{
...
[DispId(19)]
int IainTest(ref byte[] Hello);
}
}
我正在设置变量作为IDispatch :: Invoke的参数。如果Hello是 string 那么我就有:
I am setting up a variant as a parameter to IDispatch::Invoke. If "Hello" were string then I'd have:
vtParam [n].vt = VT_BSTR;
vtParam [n].bstr = ...;
如果是 ref string ,我有:
If it was ref string, I'd have:
vtParam [n].vt = VT_BSTR | VT_BYREF;
vtParam [n].bstr = ...;
如果是一个字节数组,我有:
If it was an array of bytes, I have:
vtParam [n].vt = VT_UI1 | VT_ARRAY;
vtParam [n].parray = pMySafeArrayOfBytes;
所有上述作品。
但是我在顶级示例中失败了:一个输入/输出数组参数。我试过了:
All of the above works.
But I'm failing on the top example: An in/out array parameter. I've tried:
vtParam [n].vt = VT_UI1 | VT_ARRAY | VT_BYREF;
vtParam [n].parray = pMySafeArrayOfBytes;
但我在COM编组代码中崩溃了。看看程序集,它似乎正在检查VT_ARRAY,屏蔽VT_ARRAY,然后查看剩下的内容 - 这不是一个简单的类型。
任何提示?
Iain。
But I get a crash in the COM marshalling code. Looking at the assembly, it appears to be checking for VT_ARRAY, masking out VT_ARRAY, then looking at what's left - and that's not a simple type.
Any tips?
Iain.
推荐答案
如果有效
if that works
vtParam [n].vt = VT_UI1 | VT_ARRAY;
vtParam [n].parray = pMySafeArrayOfBytes;
不要使用VT_BYREF标志。这将传输一个指针,该指针在另一个进程中无效/无法访问。
将编组视为包服务,它想要传递数据包而不是引用数据。 。
dont use the VT_BYREF flag. This will transport a pointer, which is invalid/inaccessable in another process.
Consider marshalling as a "package service" which want to deliver packets od data not references...
在VARIANT结构中,您将看到MSDN中没有任何文档的名为pparray的成员。我尝试使用它将SafeArray传递给SAFEARRAY **(在idl中)参数,如下所示:
In VARIANT structure, you will see member named pparray without any document in MSDN. I try to use it to pass an SafeArray to SAFEARRAY** (in idl) parameter, like this:
vtParam[n].vt = VT_I4 | VT_ARRAY | VT_BYREF;
vtParam[n].pparray = &mySafeArrayPointer; // use address of your safeArrayPointer
请记住释放它〜
Remember to free it~
这篇关于在调用“ref byte []”时设置IDispatch :: Invoke的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!