passing char array to DLL
This is a small example. It might be helpful.
MQL5 code
#property script_show_inputs #import "MQL5DLLSamples.dll" int fnCalcSum(char &arr[],int size); #import //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { char arr[]; int res=0; ArrayResize(arr,100); for(int i=0;i<ArraySize(arr);i++) { arr[i]=(char)i; res+=i; } Print("MQL5 res:",res,", library res: ",fnCalcSum(arr,ArraySize(arr))); } //+------------------------------------------------------------------+
Library is attached.
Result.
2011.08.11 11:00:00 tmp (EURUSD,H1) MQL5 res:4950, library res: 4950
Files:
MQL5DLLSamples.zip
4 kb
alexvd:
This is a small example. It might be helpful.
MQL5 code
Library is attached.
Result.
thank you. your sample works. short:
char &arr[]
Hello,
can anyone tell me how to pass a char array to a DLL.
Those articles can't help:
https://www.mql5.com/en/forum/1739/14654#comment_14654
https://www.mql5.com/en/articles/18
the situation:
the DLL function is declared by:
void __stdcall read_char_array(char* array,int arraysize);
in MQL5 header declares this function:
void read_char_array(char& buf,int size);
MQL5 code:
char dll_param[100];
read_char_array(dll_param,99);
compiler error:
'dll_param' - parameter conversion is not allowed
'dll_param' - array access error
anyone knows what's wrong ?
Thank you