Discussion on "How to write a DLL for MQL5 and exchange data in 10 minutes". - page 6
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
Usewchar_t instead of char
The problem lies in the mql itself.
What kind of code is this? Copying a pointer is just copying 4 bytes of memory containing the address.
In this case, memcpy can help you, if you take care of the allocation of the necessary buffer in the receiving line beforehand (in the MQL5 program).
What kind of code is this? Copying a pointer is just copying 4 bytes of memory containing the address.
In this case, memcpy can help you, if you take care of allocation of the required buffer in the receiving line (in MQL5 program).
What has the pointer got to do with it? This code works perfectly in mql4. Not after migration to mql5.
Everyone here is giving advice, but I wish one showed a really good example of how to pass the string from mql5 to dll function.
...
Question
What's the problem? How to humanly pass a string from MQL to dll?
1) Thank you for your message. The error has been fixed. Please wait for an update.
2) You have been correctly told about wchar _t - the strings in MQL5 are Unicode.
3) What do you mean "When checking in visual debug"?
4) This is the correct way to use it:
Thank you for helping struggling programmers like me. :) Your example has brought some clarity to my situation.
I have decided to write (or eighth, who may need it) function to convert string from wchar_t to good old char. This function may be useful to those whose projects have a lot of code that uses the char type. And since MQL5 passes only wchar_t, it's easier to convert at the input than to rewrite half of the dll code.
Thank you for helping struggling programmers like me. :) Your example has brought some clarity to my situation.
I have decided to write the function to convert a string from wchar_t to good old char. This function may be useful to those whose projects have a lot of code that uses the char type. And since MQL5 passes only wchar_t, it's easier to convert at the input than to rewrite half of the dll code.
DLL functions that accept strings as char *, of course, take a pointer to the first element of the array of char type. This means that when describing the import of such functions in MQL5 program, we should use the char array as a string parameter.
For these cases, we have provided the StringToCharArray function that correctly converts strings in the national alphabet. The wcstombs function does not always do this correctly.
The article is interesting and useful.
1) The fact that the source code is included is cool. Heh, but where is the compiled DLL? Obviously, it's not a problem for a Megaproger to create it.
But what if I'm not a Mega and not a Proger?! :)
2) The article uses an MS compiler. I'm not friendly with it:) I have BC++. Can you post the source code tuned for it?
(IMHO, probably, it is always better to post sources for MS and BC, they are two leading companies, but their writing styles are different).
We try not to post potentially dangerous code (DLLs) so as not to make users nervous. Besides this is just a test example.
Unfortunately, I don't have Borland C++ compiler at hand. Try to adapt it yourself, it's less than one page of code.
yu-sha:
Aren't the developers setting their sights too high?
And why reinvent the wheel when everything has already been done a long time ago (C, Delphi, ...)?
One should not do what seems right, but what is beneficial. Because profitability is what is right. And in this case (MT5+MQL5+services) - a huge profit (will be repaid tens or hundreds of times) for MetaQuotes and a huge profit for traders. Just not right away.
It's always good to look wide and ahead for at least 5 years. MetaQuotes has done just that.