将 VB6 变体分配给对象
我有一个使用 C# 编译的 Dll 的 VB6 应用程序。我已经通过 COM 成功地完成了这项工作。 但我的问题是我有一个 Variant 数组,其中包含 String 和 Double 数据类型。我需要将此数组传递给我的 C# Dll,它以对象形式接收该数组。 因此,我需要做的就是将 Variant 数组转换为 C#“可以理解”的对象数组。有人对此有任何线索吗?
I have a VB6 application that uses a C# compiled Dll. I have been successfull in making this work by means of COM.
But my problem is that I have a Variant array with String and Double data types inside it. I need to pass this array to my C# Dll, which is receiving the array as an Object.
So, all I need to do is to convert the Variant array into an Object array "understandable" by C#. Anyone has any clue on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
object[] System.Runtime.InteropServices.Marshal.GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
您尝试过这种方法吗?
我自己没有尝试过,但似乎它会成功。
object[] System.Runtime.InteropServices.Marshal.GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
Have you tried this method?
Haven't tried it myself but seems like it would do the trick.
这是 C# 函数声明:
这是 VB6 调用:
其中
data1
和data2
是 Variant 数组。我不认为我能在 C# 上做太多事情,就像你们所说的那样,一旦我在函数调用中遇到的错误是“无效的过程调用或参数”。 VB6方面有什么选择吗?
感谢您的所有回复。
This is the C# function declaration:
This is the VB6 call:
where
data1
anddata2
are arrays of Variant.I don't think I can do much at the C#, like you guys are saying, once the error I get at the function calling is "Invalid procedure call or argument". Any option at the VB6 side?
Thanks for all the replies.
这应该可以解决问题
This should do the trick
这必须从 C# 方面直接完成;如果不是,那么 VB6 就无能为力。也就是说,默认情况下,这样声明的方法:
从 VB6 中将被视为采用
Variant
数组(或者,在 IDL 级别上,为SAFEARRAY(VARIANT)
) 。如果它不适合您,那么您的 C# 声明就有问题 - 请将它们发布出来,以便进行审查。
This has to be done right from C# side of things; if it's not, then there isn't much you can do from VB6. That said, by default, a method declared like this:
will be seen from VB6 as taking an array of
Variant
(or, on IDL level, asSAFEARRAY(VARIANT)
).If it doesn't work that way for you, then there's something wrong with your C# declarations - please post them so they may be reviewed.