Most useful and informative article regarding working with external DLL APIs. Thank you so much.
Example 4. Copying the structures by means of MQL5 struct str1 { double d; // 8 bytes long l; // 8 bytes int i[3]; // 3*4=12 bytes }; struct str2 { uchar c[8+8+12]; // str1 structure size }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { str1 src; src.d=-1; src.l=20; //--- filling the structure parameters ArrayInitialize(src.i, 0); str2 dst; //--- turning the structure into the byte array dst=src; }
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:
struct str1 { double d; // 8 bytes long l; // 8 bytes int i[3]; // 3*4=12 bytes }; struct str2 { uchar c[8+8+12]; // str1 structure size }; union union1 { str1 src; str2 dst; }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { union1 u; u.src.d=-1; u.src.l=20; //--- filling the structure parameters ArrayInitialize(u.src.i, 0); //--- the byte array representing the structure is in dst.c ArrayPrint(u.dst.c);

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
New article Getting Rid of Self-Made DLLs is published:
Author: Alex Sergeev