Download MetaTrader 5

passing char array to DLL

To add comments, please log in or register
Do you know that MQL5 can create custom graphical tools?
chinaski
890
chinaski 2011.08.10 22:29 

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

qestion about passing the array of string into DLL
  • www.mql5.com
so , my question is how to access the element in a string's array .
Alexey Da
Moderator
6599
Alexey Da 2011.08.11 11:02  

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:
chinaski
890
chinaski 2011.08.11 16:58  
alexvd:

This is a small example. It might be helpful.

MQL5 code

 

Library is attached.

Result.

 thank you. your sample works. short:

char &arr[]

To add comments, please log in or register