Questions from Beginners MQL5 MT5 MetaTrader 5 - page 855

 

It's important for me to get an answer to my questions.

For CTrade::Buy, CTrade::Sell, CTrade::ClosePosition methods

Does it mean that if false is returned, Retcode should be ignored?

Does it mean that if true is returned, Retcode is always filled with correct value?

Thank you.

 

Colleagues, help me out.

I'm trying to figure out how to work with registry, I've made a simple Expert Advisor for the test. Reading data from system registry goes without problems, but there are problems with writing, MT and memory crashes... (((

Maybe my eye is already soaked and I don't see the obvious...

Files:
TestReg.mq5  25 kb
 
Алексей Барбашин:

Colleagues, help me out.

I'm trying to figure out how to work with registry, I've made a simple Expert Advisor for the test. Reading data from system registry goes without problems, but there are problems with writing, MT and memory crashes... (((

Maybe my eye is already soaked and I don't see the obvious...

It should be simple here. Before and after each call to API function print something to log. After the crash, the logs will show where the crash happened.

 
. ... Rick D. ... .:

It should be quite simple. Before and after each call of API function print something in log. After the crash it will be clear from logs where the crash happened.

This way the log doesn't even have time to be written, the terminal closes with an error. (( I assume that there is a memory leak. But dynamic objects are not used (new). I don't know how to cope with it and look for such troubles ;(.

 
Алексей Барбашин:

So the log doesn't even have time to be written, the terminal closes with an error. (( I assume that there is a memory leak. But dynamic objects are not used (new). I don't know how to cope with it and how to detect such problems ;(

I may have tweaked your example a bit.
Files:
TestReg.mq5  26 kb
 
. ... Rick D. ... .:
I tweaked your example a bit.

Я ... shocked, pleasantly shocked. Put your change on several charts at once to ensure asynchronous load on registry.... Everything is working consistently. You changed the principle of parameter passing in the API, that is, where return values are used, there you applied arrays with passing by reference, which in mql means passing an address, or pointer in terms of++. But I thought this approach, described 10 years ago, as anachronistic, because all simple data types in API are anyway passed by reference.... But apparently it was my mistake and shortsightedness, it means that simple types are not so painlessly passed to API. Thank you very much for pointing me in the right direction! )))

 
Алексей Барбашин:

Я ... shocked, pleasantly shocked. Put your change on several charts at once to ensure asynchronous load on registry.... Everything is working consistently. You changed the principle of parameter passing in the API, that is, where return values are used, there you applied arrays with passing by reference, which in mql means passing an address, or pointer in terms of++. But I thought this approach, described 10 years ago, was anachronistic, because all simple data types in API are passed by reference.... anyway. But apparently it was my mistake and shortsightedness, it means that simple types are not so painlessly passed to API. Thank you very much for pointing me in the right direction! )))

Some time ago under MT4 I was taught to pass pointers to API functions via one-dimensional arrays. If something has changed at the moment, and someone can confirm it, I'll use new approach.

But you still had the types messed up. In particular, longs in Windows and in MQL5 have different sizes.
Maybe you will find some other differences.

 
. ... Rick D. ... .:

Once upon a time under MT4 it was taught to pass pointers to API functions via one-dimensional arrays. If anything has changed at the moment and someone can confirm it, I will use the new approach.

But you also had some confusion with the types. In particular, longs in Windows and in MQL5 have different sizes.
Maybe you will find some other differences.

I have seen all the differences))) Thank you very much!

The only question is about the size of data stored in the registry. According to the example from the documentation (https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911(v=vs.85).aspx), we can store a bit more data than in the corrected file (ushort buff[1024];). Do I understand it correctly?
RegQueryValueEx function (Windows)
  • msdn.microsoft.com
Retrieves the type and data for the specified value name associated with an open registry key. To ensure that any string values (REG_SZ, REG_MULTI_SZ, and REG_EXPAND_SZ) returned are null-terminated, use the RegGetValue function. Syntax Parameters hKey [in] lpValueName [in, optional] The name of the registry value. If lpValueName is NULL or an...
 
Алексей Барбашин:

I saw all the differences))) Thank you very much!

The only question is about the size of the data stored in the registry. According to the example from the documentation (https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911(v=vs.85).aspx) you can store a bit more data than in the fixed file (ushort buff[1024];). Am I reading it right?
Correct. There can be more data. For large data, it is correct to request length first, then dynamically resize the array, then get all the data.
 
. ... Rick D. ... .:
Right. There can be more data. For big data, it's correct to request length first, then dynamically resize the array, then get all the data.

Hmmm... I probably didn't look at the API very carefully, but I didn't see such a function.... And it would probably be handy.

Any other tips... perhaps the question is too ... ridiculous... How do I translate a number, e.g. double, into an array char? That is, in some API it's required to pass numbers as a pointer. Pointers are passed as one-dimensional arrays... It's clear with strings, the StringToShortArray and StringToCharArray functions are provided for them, but with numbers I still don't understand how to convert them to byte arrays (char).

Reason: