DLLs and arrays.

 

Hi, I am having problems with passing arrays to DLLs and would like to know what to do. Here is an oversimplified example script.


#import "mydll.dll"
double SecondValFromDLL(double p[]);
#import

double SecondVal(double p[]) {
    return (p[1]);
}

int start() {
    double p[5] = {1.0,2.0,3.0,4.0,5.0};

    Alert("p[1] = ", SecondVal(p)); // This works, returns 2.0
    Alert("p[1] = ", SecondValFromDLL(p)); // This works, returns 2.0

    Alert("Close[1] = ", SecondVal(Close)); // This works, returns Close[1]
    Alert("Close[1] = ", SecondValFromDLL(Close)); // This does not work!!! NULL pointer.


    return (0);
}

After debugging the dll, I found that I was getting a valid pointer on the first case and a NULL pointer on the second case. Note that the problem is only when the array is passed to the DLL and not when its passed to the MT4 function.


What am I missing here?


[EDIT]


If I use ArrayCopy to copy the Close Array things work. My guess is that the internal arrays do not work with DLLs.

Reason: