Two-way array from DLL (Works in custom indicator but not in MA)??

 

I am passing in an array of data to a custom DLL function and modifying it before passing it back to MT4. The function is defined in my DLL as:

MT4_EXPFUNC int __stdcall tmpMA(const RateInfo* rates, double* out, int period, int method, int applyTo, int length);

And in my mqh file as follows:

int tmpMA(double rates[][6], double& out[], int period, int method, int applyTo, int length);

Then I am calling the function like this:

double _buffer1[];

// get the rates

double rates[][6];

ArrayCopyRates(rates);

// run the MA

tmpMA(rates, _buffer1, 10, 0, 0, Bars);

This works fantasticly in my custom indicator code but if I run the exact same code in my MA I get a crash from the DLL. It seems the memory is not valid and throws an access violation exception.

The interesting thing is that if I define a fixed length array such as double _buffer1[65000] the code runs without any crashes. But with a notable difference, the array is now the reverse of the custom indicator code.

This raises some interesting questions, for example how exactly do variable size arrays work in MQ4 and what is the difference between how they work in custom indicators and expert advisor?

Could someone please shed some light on this subject to stop me going totally mad?!

Thanks!

 

Hi mikeduk,

Watch this +/- 30 minutes video, if the video load faster you may want to skip the first 15 minutes and just watch the rest 15

www.psnouvion.com/projects/view/mt4_sample_dll

 

Thanks for the tip!

The video doesn't explain why MT4 treats DLL calls differently between indicators and expert advisor but it does suggest a solution to the problem.

I've now re-coded my EA to use the iCusom indicator instead of calling the function directly!

Thanks again!

Reason: