Click to See Complete Forum and Search --> : Problem passing an array


jkepler
June 5th, 2009, 06:55 AM
Hi,

I have the following problem: I have a routine in C/C++ (compiled in a DLL) in the form of:


void function1(double rrd[],...){...}


I want to pass an array from VB6 to that routine. So I have the following routine in VB6:


Private Sub function1 Lib "test.dll" (ByRef rrd as double,...)


and I call it:


Dim dat(6)
...
Call function1(dat(0),...)


The problem is that when I call it from VB6 I get always an error - VB6 crashes.

Any suggestions?

Kind regards,

JKepler

davidpmp
June 6th, 2009, 09:06 AM
your array have six elements from 0 to 5 but you put only first element to pass method and first element is not an array then crash is your result

jkepler
June 6th, 2009, 10:03 AM
Hi,

How should I solve the problem then? Pass the values one by one? What if the array has 200 elements?

Kind regards,

JKepler

davidpmp
June 6th, 2009, 01:46 PM
pass all elements if the method parameter is an array.I don't know VB so I write in c++


void FunctionSample(double arDouble[])
{

}
void Main()
{
double arDoubles[] = double[10];
FunctionSample(arDoubles[0]);//it's wrong. we should pass an array not an element of array.
FunctionSample(arDoubles);//error solved. we passed an array and work perfectly.
}