Reputation: 3907
Is there a way to return a struct from an imported function in MQL4, without having to pass it as a parameter and making a memcpy?
Upvotes: 1
Views: 1112
Reputation: 1
Be cautious with any kind of DLL-interfacing, MQL4 Documentation states:
Passing Parameters
All parameters of simple types are passed by values unless it is explicitly indicated that they are passed by reference. When a string is passed, the address of the buffer of the copied string is passed; if a string is passed by reference, the address of the buffer of this string without copying it is passed to the function imported from DLL.
Structures that contain dynamic arrays[], strings, classes, other complex structures, as well as static or dynamic arrays[] of the enumerated objects, can't be passed as a parameter to an imported function.
When passing an array to DLL, the address of the beginning of the data buffer is always passed (irrespective of theAS_SERIES
flag). A function inside a DLL knows nothing about theAS_SERIES
flag, the passed array is a static array of an undefined length; an additional parameter should be used for specifying the array size.
More glitches apply... Then how to make it work?
Maybe a straight, heterogeneous multi-party distributed processing, which communicates rather results than function calls, independent of all nightmares of maintaining just DLL-imported functions API changes, is a way safer way to go. Using this approach for the last few years and since than have no problems with New-MQL4.56789
string
-s that seized to remain string
-s and silently started to become struct
-s etc.
Worth to know about.
Upvotes: 0