Errors, bugs, questions - page 2580

 
Koldun Zloy:

1. In MQL a string, not a pointer, is copied.

_DLLAPI void fnReplaceString(wchar_t * text, wchar_t *from, wchar_t * to)
{
   wchar_t * cp;
   
   //проверка параметров
   if(text==NULL || from==NULL || to==NULL) return;
   if(wcslen(from)!=wcslen(to))             return;
 
   //поищем подстроку
   if((cp=wcsstr(text,from))==NULL)         return;

   //заменим
   memcpy(cp,to,wcslen(to)*sizeof(wchar_t));
}
#import "MQL5DLLSamples.dll"
void fnReplaceString(string & text, string from, string to);
#import


Section 3.3

 
Koldun Zloy:

2. You highlighted a 200 character line in MQL. Then you copied 164 characters into it. After that, look at the size of the string in MQL. It remains 200.

Length, not size! Length in characters, size in bytes.
Checked, after getting a string of 164 characters, yes the length is still 200.
Any thoughts on this?

 
Roman:

So to make it right, I gave up memcpy, and used wcscpy or wcsncpy.
Result, post above.

I meant sizeof( wchar_t* ).

 
Roman:


Section 3.3

You would be better off not arguing with me, but reading this article more carefully. And figure out what is going on there.

Then you won't have any problems.

What you want to do is really not that complicated.

 
Roman:

Length, not size! Length in characters, size in bytes.
Checked, after getting a string of 164 characters, yes the length is still 200.
Any thoughts on this?

Why this is the case has already been explained above.

 
Koldun Zloy:

What you want to do is really not that difficult.

So tell me if it's not so difficult.
Or do you think this is normal behaviour?

 
Roman:

So tell me if it's not so difficult.
Or do you think this is normal behavior?

So you don't even plan to understand anything, just give you a ready-made recipe and that's it?

I don't understand why you would want to do programming if it's a burden for you, but that's up to you.


Do you think anyone will want to help you if you ask a question and don't want to show a detailed reproducible code,

or don't read it, or argue with those who know much more?


Therefore, there won't be a ready recipe. I'll write a general principle of getting a string from a DLL. You can write the code yourself, if you consider yourself a programmer.


1. In MQL you create the ushort array.

Initialize it.

3. Pass the array and its size to DLL.

4. In the DLL, copy a string to this array using the wmemcpy_s() function.

5. Return the length of the copied string from the DLL.

6. In MQL, create a string from the array using the ShortArrayToString() function.

 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 

On one of the servers (not MQ) MT5 goes crazy - it loads the CPU to 100% and intensively logs these messages for different instruments:

HistoryBase constant spontaneous updating

Charts are blinking. It is impossible to work.

Is there any possibility to fix it locally or the only way out - to wait for the server to finish some games?

 
Koldun Zloy:

So you don't even plan to understand anything, just give you a ready-made recipe and that's it?

I don't understand why you would want to do programming if it's a burden for you, but that's up to you.

Do you think anyone will want to help you if you ask a question and don't want to show a detailed reproducible code,

or don't read or argue with those who know much more?

Therefore, there won't be a ready recipe. I'll write a general principle of getting a string from a DLL. You can write the code yourself, if you consider yourself a programmer.


1. In MQL you create the ushort array.

Initialize it.

3. Pass the array and its size to DLL.

4. In the DLL, copy a string to this array using the wmemcpy_s() function.

5. Return the length of the copied string from the DLL.

6. In MQL, create a string from the array using ShortArrayToString().

Where do you see an argument here? This is a working discussion, no need to twist the meaning into a hen house, with arrogant pathos.
You didn't ask for anything ready-made. I thought you and the pointer had a solution, but you didn't.
You're the one who hasn't read the subject; it's been discussing arrays here for a long time already, and everyone knows about it very well.
And I've been leaning towards arrays for a long time. But since mql has string, why not use it directly?
It is this very bug in mql's string, i.e. copying of a pointer into it, that we're discussing here.
I'll tell you more, it's not only through ushort that everything can be solved. There are many options with arrays.
But in my case I don't want to use arrays, since the code structure doesn't always make sense.
All the more so when I have mql's string that I can work with directly, but it must work correctly.

Reason: