如何将数组从VB传递给C ++组件 [英] How do I pass an array from VB to C++ component

查看:75
本文介绍了如何将数组从VB传递给C ++组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VB代码,它试图将一个数组传递给C ++组件。它在少数情况下不起作用。问题在于函数调用中的括号。



VB代码:

I have a VB code given which tries to pass an array to C++ component.It doesn't works in few cases. The issue is with the parenthesis in the function call.

VB code:

Dim arr(2) as Long
arr(0) = 32678
arr(1) = 0
arr(2) = 0

//different calls for the C++ function to pass the above array as parameter

sample_Function arr              // No parameter is received C++
sample_Function (arr)            // Parameter is received C++
Call sample_Function(arr)        // No parameter is received C++
Call sample_Function((arr))      // Parameter is received c++



C ++代码:




C++ code:

(STDMETHOD)sample_Function (VARIANT* arrray);  // this is the declartion in C++

sample_Function (VARIANT* array)
{
....
}

我们可以看到如果括号指定调用工作正常,但没有括号也应该工作。不知道是什么问题。



我尝试了什么:



根据MSDN,Vb中的传递数组应该是C ++模块中的Variant。这是我实施的相同。它工作正常,但如果只删除括号,我们可以看到错误。

还调试代码,当函数调用时没有括号,可以看到* array保存错误消息Invalid Safearray

We could see like if parenthesis specified the call works fine, but without parenthesis also should work. Any idea what is the issue.

What I have tried:

As per MSDN the passing array from Vb should be as Variant in C++ module. which is the same i've implemented. It works fine, but if only the parenthesis removed we could see the error.
Also debugged the code, when the function called without parenthesis and could see like * array holds error message "Invalid Safearray"

推荐答案

你最好写一下

You should better write
Dim arr(2) as Variant



并继续。



调试器只能解析有效的内存到数据类型。所以无效的Safearray意味着数据不是这样的Safearray。听起来很愚蠢,但这是事实。



我希望它有所帮助。


and proceed.

The debugger can only resolve valid memory to data types. So "Invalid Safearray" means that the data isnt such a Safearray. Sounds stupid, but it is the truth.

I hope it helps a bit.


这篇关于如何将数组从VB传递给C ++组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆