fx_maddin: Hopefully it is possible and I am on the right way.
Lets say I have a function within a DLL:
double ReturnArray() { double aReturn[2]; aReturn[0] = 1.34567; aReturn[1] = 1.35678; return(*aReturn); }
Now, I would like to work with this array in MQL
But MetaEditor said while compiling:
double myArr[2] = ReturnArray(); Comment(myArr[0],myArr[1]);
'(' - unexpected token
- The MOMENT your ReturnArray() returns, the aReturn is gone off the stack and your return pointer is BOGUS. (If it was static or global or on the heap, maybe.)
- A mql4 function can only return a variable. Not an array.
double myArr[2]; ReturnArray(myArr); Comment(myArr[0],myArr[1]);
void ReturnArray(double *aReturn) { aReturn[0] = 1.34567; aReturn[1] = 1.35678; return; }
You can return array as a parameter of the function. I use that with great success. Writing my dlls using delphi but the idea is the same. You send a pointer to an array as a parameter and read the parameter after the function call.
void ReturnArray(double& Arr[2]); ..................... double MyArray[2] ReturnArray(MyArray); Comment(MyArray[0],MyArray[1]);
WHRoeder,
your code
double myArr[2]; ReturnArray(myArr);
gives also error message
')' - left square parenthesis expected for array ')' - parameter expected
cyberfx.org,
void ReturnArray(double& Arr[2]);
in Visual C++ 2010 Express said
error an array reference is not allowed
I'm currently not sure what to do. I am absolutly newbie to C++
I have solved it this way:
MQL:
double myArr[2]; if (ChangeMyArr(myArr)==true) { Comment(myArr[0],myArr[1]); }
DLL:
bool ChangeMyArr (double *myArr) { myArr[0] = 1.12345; myArr[1] = 9.87654; return(true); }
This works for me
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
hopefully it is possible and I am on the right way.
Lets say I have a function within a DLL:
Now, I would like to work with this array in MQL
But MetaEditor said while compiling:
'(' - unexpected token
How can I get rid of this issue?
thanks in advance