08-31-2009 03:23 PM - edited 08-31-2009 03:26 PM
I have created a .NET controller to interface with CVI. I am passing a 2-D array from CVI to .NET, but am getting an out of bounds exception.
Does .NET handle multidimensional arrays in a different way? I looked into it and found that vb.NET allocates memory differently for multidimensional arrays.
I am using CVI .NET library functions to allocate memory, but am unsure why the arrays I'm passing are not being sent properly. Can someone shed some light
on this issue. Attached is my .c and .h file from CVI along with my instrument.
NOTE: Youll need to reload the instruments from the vb.net project and put the executable into the windows assembly GAC.
Solved! Go to Solution.
09-01-2009 10:14 AM - edited 09-01-2009 10:16 AM
Try this. Sorry, not much commenting.
#include <cvidotnet.h>
#include "vbMath.h"
#include <cvirte.h>
static CDotNetHandle exceptionHandle;
static vbMathDLL_mathClass classHandle;
void init()
{
double * result;
double *myArray;
int i,p;
Initialize_vbMathDLL();
vbMathDLL_mathClass__Create (&classHandle, &exceptionHandle);
result=CDotNetAllocateMemory(sizeof(double));
myArray = CDotNetAllocateMemory(sizeof(double)*5*5);
for(i=0;i<5;i++)
for(p=0;p<5;p++)
{
*myArray = p;
myArray = myArray +1;
}
myArray=myArray-25;
vbMathDLL_mathClass_addArray (classHandle, myArray, 5, 5, 5, 5, result, exceptionHandle);
CDotNetDiscardHandle(classHandle);
CDotNetDiscardHandle(exceptionHandle);
Close_vbMathDLL();
}
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
init();
return 0;
}
----------------------
Imports System.Reflection
Public Class mathClass
Dim globalVal As Double
Public Sub addArray(ByVal array(,) As Double, ByVal x As Integer, ByVal y As Integer, ByRef c As Double)
Dim i As Integer
Dim p As Integer
c = 0
For i = 0 To x - 1
For p = 0 To y - 1
c = c + array(i, p)
Next
Next
End Sub
End Class