Old topic but no answers on the internet yet. Here it comes:
Way less complicated. You use IntPtr within C# and declare the import-section with the struct. Thats it. To copy the data you use memcpy() of msvcrt.dll.
[DllExport("Whatever_with_struct", CallingConvention = CallingConvention.StdCall)] public static void Whatever_with_struct(IntPtr structData, int structSize) { }
and within MQL
struct mystruct { double d1; int i1; long l1; } #import "mydll.dll" void Whatever_with_struct (mystruct &data, int size); #import mystruct mydata; Whatever_with_struct(mydata,sizeof(mystruct));
In case the struct is the same in C# and MQL, you dont even need the sizeof() term.
And of course that works with MQL5 and MQL4. Just compile the DLL separately for 64 and 32 bit.

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
I am writing a script in MQL4 language for Metatrader 4 which is using C# DLL library for further data processing.
What I'm trying to do is to pass an array of following MQL structures:
to this function in C# DLL:
This is the function definition on MQL side:
and this is the structure on C# side:
My problem is that it is not working when calling HistoricMarketData from MQL. The script either crashes whole Metatrader program or throws an exception and fails.