Nobody knows how to do this ?
Have a DLL which returns ANSI strings (const char*).
I need to convert those into Unicode string for MQL5.
Function is delcared
string my_function(string buf,string id);
In c++ function is delcared
const char* __stdcall my_function(const char* x,const char* y)
In MQL5 code, i use these functions to make the conversion:
http://mqlmagazine.com/mql-programming/dll-hell-mql5-edition-unicode-vs-ansi/
The point is that SOMETIMES return string is correct and sometimes empty (like having leading zero).
The function above logs each input and output and the log shows there is a non empty string returned where MQL5 strings seems to be empty.
Has anyone knowledge about ? Please do not point to the function wrong declared in DLL. This is correct.
It must be related how the function should be declared in MQL5 or there is some basic implementation of string in MQL5.
Thank you
Also, the desk never answer. ...
- mqlmagazine.com
Additional information:
The logfile of DLL shows this:
my_function;param0=;100=115;1150=4221485.57000000;1151=-13.77000000 param1=100 ret=115
so it returns 115.
When calling in MQL5
string param0=U2A(";100=115;1150=4221485.57000000;1151=-13.77000000"); string param1=U2A("100"); string ret= my_function(param0,param1); /// ret=115=115
so only devil knows why 115=115 returned instead of 115 (like log shows)
Finally, the string returned is empty or wrong or sometimes correct.
- 2010.01.27
- MetaQuotes Software Corp.
- www.mql5.com
Hello,
thank you for link but it is no help . The DLL works perfect and proven when working with MT4 and ANSI strings and MT5 without strings.
The only interesting thing of this link is how to pass strings:
_DLLAPI void fnReplaceString(wchar_t *text,wchar_t *from,wchar_t *to)
My dll uses const wchar_t* instead. Also, some return const wchar_t* (allocated of course).
When doing tests - so loading DLL in another c++ program - i can convert to ansi and vice versa - no problem.
Only with MQL5 - there is a problem. I did not figured out what the reason was.
Summary: Methods listed here
http://mqlmagazine.com/mql-programming/dll-hell-mql5-edition-unicode-vs-ansi/
work not reliable in my case, that is getting ANSI string converted correctly (when returned from DLL function) and strings (MQL5) converted corretly into ANSI (when passed to DLL function).
I wrote my own conversion functions and it seems to work now (using MFC)
const char* __stdcall UnicodeToAnsi(const wchar_t* us) { boost::recursive_mutex::scoped_lock l(dll._mutex_conversion); CString& as = dll._RetBuf.Get(""); // get reference to allocated ansi string USES_CONVERSION; as=W2A(us); // convert into ansi return as; } const wchar_t* __stdcall AnsiToUnicode(const char* as) { boost::recursive_mutex::scoped_lock l(dll._mutex_conversion); _bstr_t& us=dll._WRetBuf.Get(as); // get reference to allocated unicode string return us; }
You may also provide wchar_t* interface for your functions directly but then you need to implement different for MT4. My goal is a DLL which provides some service functions for MT4 as well as for MT5.
- mqlmagazine.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
i have a custom DLL returning ANSI string. How to delcare this function in .mqh file please ?
const char& myfunc() - error
const char[] myfunc() - error
const char* myfunc() - error
char& myfunc() - error
char[] myfunc() - error
char* myfunc() - error
how to do this ?
Thank you