简体   繁体   English

将双数组从Visual Basic传递到C ++ DLL

[英]Passing double arrays from Visual Basic to C++ DLL

I am trying to pass two double arrays from a handler that's written in VBA into the DLL written in C++ and I keep getting an error saying the index it outside the bounds of the array. 我试图将用VBA编写的处理程序中的两个双精度数组传递到用C ++编写的DLL中,但不断收到错误消息,说它在数组的界限之外。 The arrays contain 800 double values which I need to calculate the correlation between the two arrays using the FFT 数组包含800个double值,我需要使用FFT计算两个数组之间的相关性

function call in the VBA code: VBA代码中的函数调用:

Dim firstDataDbl() As Double = Array.ConvertAll(firstData, Function(d) Double.Parse(d))
Dim secondDataDbl() As Double = Array.ConvertAll(secondData, Function(d) Double.Parse(d))
rdftTest(UBound(firstDataDbl) + 1, firstDataDbl(0), secondDataDbl(0))

definition of the DLL function in VB: VB中DLL函数的定义:

Public Module DLLTest
   <DllImport("FFT.dll", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Cdecl)>
   Function rdftTest(ByVal length As Integer, ByRef firstDataDblFirstElement As Double, ByRef secondDataDblFirstElement As Double) As Integer
   End Function
End Module

Function, written inside the C++ DLL: 在C ++ DLL中编写的函数:

void rdftTest(int length, double *input1, double *input2) {
   std::ofstream myFile;
   myFile.open("C:\\randFolder\\foo.txt", std::ios::out);
   myFile << length << " " << &input1 << " " << &input2 << std::endl;
}

Both arrays are always of equal length which is why i'm using only one length argument. 两个数组的长度总是相等的,这就是为什么我只使用一个length参数的原因。

我通过将UBound(firstDataDbl) + 1解析为Integer解决了该问题,然后在函数中传递了该值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM