Download MetaTrader 5

How to import DLL that returns array

To add comments, please log in or register
Lexeon
14
Lexeon  

I have a DLL that will return a pointer to an array of structs:

struct dataSet{

        //some random variables

}; 

dataSet* RandomFunction(const int ratesTotal, const double price[]) { 

        //some random calculations

}

However, I do not know how to import this function in mql5. I have tried doing

#import "RandomDLL.dll"
   dataSet[] RandomFunction(const int ratesTotal, const double& price[]);
#import

 However when I compile my code I get two errors:

'[' - name expected

'double' - name expected

 

I assume the 'double' error is just residue from the return type not being correct. Does anyone know how to properly import a function from a DLL that returns a pointer to an array? 

Lexeon
14
Lexeon  
It seems that it doesn't matter if I'm trying to return an array or not. I get the error if I even try to return just a single struct, but it compiles if I change the return type to an int or a float.
Stanislav Korotky
18238
Stanislav Korotky  
AFAIK, you can't import structs from DLLs. Use standard types instead. To return an array of doubles, for example, you should pass array of doubles by reference into DLL function and it will fill it with output.
To add comments, please log in or register