yes , i have read , and i know i can pass a string with the form f(string& str) ;
but i found i can not pass the array of strings , eff f(string& sting[]) ;
so if i can not access the string's array of MT5 in DLL .
thanks .
In this section MQL5 Help is written:
Classes, string arrays or complex objects that contain strings and/or dynamic arrays of any types cannot be passed as a parameter to functions imported from DLL.
But you can use array of char for ANSI string declaration.
MQL5 script:
//+------------------------------------------------------------------+ //| Array_strings.mq5 | //| Copyright 2010, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2010, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" struct char_array { char a[256]; char b[256]; char c[256]; }; char_array my_ar; #import "mylib.dll" void f(char_array &my_ar); //pass structure which contains the ANSI strings #import //+------------------------------------------------------------------+ void OnStart() //+------------------------------------------------------------------+ { // initialize strings string str1="first string"; StringToCharArray(str1, my_ar.a); str1="second string"; StringToCharArray(str1, my_ar.b); str1="third string"; StringToCharArray(str1, my_ar.c); func(my_ar);// print and change first string (my_ar.a) in MQL code f(my_ar); // change first string (my_ar.a) in DLL code Print(CharArrayToString(my_ar.a)); } //+------------------------------------------------------------------+ void func(char_array &my_ar) //+------------------------------------------------------------------+ { string str; str = CharArrayToString(my_ar.a); Print(str); // print string str = str + " + add string"; // change string StringToCharArray(str,my_ar.a); // save changes }
DLL code
#include <windows.h> struct char_array { char a[256]; char b[256]; char c[256]; }; void __stdcall f(char_array &my_ar) { strcpy(&my_ar.a[0], "my new string");// change string }
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,
i encounter a question about passing string's array into a DLL ,
first i declare the funtion in .mqh as follows : void f(string& array[]) ; , but this failed .
and then i try to do this by declare the function : void f(string& str) ;
with a for loop , i push string array into dll as follows :
.......
string str[5]= {"sddsa" , "ddass" , "dsdfasdwe" , "wwer2" , "e23"} ;
for(int i = 0 ; i < 5 ; i ++)
f(str[i]) ;
but in the function f , i didn't get the right value of the str[i] , and i print the address of str :
addr0 = 038C8D48
addr1 = 038C8D54
addr2 = 038C8D60
addr3 = 038C8D6C
addr4 = 038C8D78
so , my question is how to access the element in a string's array .
thanks in advance .