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
The author of the article is very grateful for such an accessible presentation of information about IPC interoperability without bicycle dlls.
Working with memory seems to me rather complicated, but the approach is clear, except for some questions, I hope knowledgeable people will help to understand:
1. With the help of memcpy we copy a two-byte variable short into the array uchar[2], how is the information put into the array itself?
What format will the values at index 0 and 1 of the uchar array be in?
The value is split by byte by by byte and written into the array, ok ... I think I understand here.
I can not understand what values fall into this array and how to get the original value from them, the question is not that I can not display these values on the screen.
2. How to properly fill the uchar[4] array with values of different types when copying memcpy, for example:
It feels like the answer is trivial and everything is done simply, but how to write it down correctly ?
Have you triedPrint?
The fourth example gives error : 'operator=' - illegal operation use SAMPLE_04.mq4 34 7
#property copyright ""
#property link ""
#property version ""
#property strict
//Пример 4. Копирование структур средствами MQL5
//---
struct str1
{
double d; // 8 байт
long l; // 8 байт
int i[3]; // 3 * 4 = 12 байт
};
//---
struct str2
{
uchar c[ 8 + 8 + 12 ]; // размер структуры str1
};
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(){
str1 src; //
src.d = -1; //
src.l = 20; //
//--- заполняем параметры структуры
ArrayInitialize(src.i, 0);
str2 dst; //
//--- превратили структуру в байтовый массив
dst = src; // <----- Ошибка
}
I understand the idea about the memory section, but maybe the definitions are not quite right?
Can you tell me what is the reason?
Thanks in advance.The idea of a memory location is clear, but maybe there is something wrong in the definitions?
What is the reason?
Structures of different types cannot be copied anymore, MQL has removed this possibility.
use union
uchar is wrong by the way, and there double is also suspiciously present there.
And by the way src should specify what exactly belongs to it and will be passed.
Someone has already corrected you just as you suggested. Good. Think. Good luck.
will it work for mql4 today?
The languages (MQL4 / MQL5) are completely the same now - the difference is in 2-3 functions missing in MQL4(ArrayPrint and something else small) and in "new features" for MQL5 - database, DirectX and OpenCL.
but the article was written 8 years ago, now MQL has become a strictly typed language, and to assign 2 structures (example in the article) you need to write a copy constructor or serialise the structure into a byte array and then back again.
Assigning structs of different types doesn't work anymore (parameter conversion not allowed - variable of the same type expected).
But it would be possible to work with unions: