C#dll,C ++客户端,传递数组参数 [英] C# dll, C++ client, pass array parameter
问题描述
你好,
我有一个C#DLL,调用如下:
Hello,
I have a C# DLL with a call like this:
[DispId(7)]
void Test([MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_BSTR)] ref string[] s);
在C ++方面,该函数称为:
On the C++ side, the function is called:
SAFEARRAY *sArr1 = NULL;
iface.Test(&sArr1);
我收到一个消息框:参数不正确."
查看输出调试窗口,我看到以下内容:
警告:正在构造COleException,scode = E_INVALIDARG($ 80070057).
有谁知道将数组作为参数,C#DLL和C ++客户端传递的其他方法吗?
任何帮助将不胜感激.
真诚的
Mike
I''m getting a message box: "The parameter is incorrect."
Looking at the output debugging window, I see this:
Warning: constructing COleException, scode = E_INVALIDARG ($80070057).
Does anyone know of other ways to pass an array as a parameter, C# DLL and C++ client?
Any help would be appreciated.
Sincerely,
Mike
推荐答案
80070057).
有谁知道将数组作为参数,C#DLL和C ++客户端传递的其他方法吗?
任何帮助将不胜感激.
真诚的
Mike
80070057).
Does anyone know of other ways to pass an array as a parameter, C# DLL and C++ client?
Any help would be appreciated.
Sincerely,
Mike
好,我找到了解决问题的方法.
OK, I found a solution to my problem.
//C# DLL
public void Test(ref object s)
{
s = new string[2] { "one", "three" };
}
//C++ call
VARIANT s = COleVariant();
BOOL b = iface.CreateDispatch( ... ); //Parameter omitted for conciseness
iface.Test(&s);
谢谢大家的努力.
Thank you all for your efforts.
诚然,我看不懂C#,但希望您无论如何都能从这篇文章中获得一些帮助.
我注意到的东西;您有一个变量 sArr1 ,它是指向SAFEARRAY的指针.当您调用 Test 函数时,该参数是指向该SAFEARRAY指针的指针.您应该这样称呼:
Admittedly, I can''t read C#, but hopefully you''ll get some help from this post anyway.
Something I noticed; you have a variable sArr1, which is a pointer to a SAFEARRAY. When you call your Test function, the argument is a pointer to this pointer to a SAFEARRAY; you should maybe call it like so:
SAFEARRAY *sArr1 = NULL;
iface.Test(sArr1);
实际上,并不是真的想使用这个双指针.
第二个想法;该消息框来自DLL内部,它可能只是在抱怨NULL值.
It''s not impossible you actually want to use this double pointer though.
Second idea; the message box comes from within the DLL, it may simply be complaining about the NULL-value.
这篇关于C#dll,C ++客户端,传递数组参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!