Discussion of article "Exposing C# code to MQL5 using unmanaged exports" - page 2

 

Great article, very, very handy. But...

I have a slight bug with Visual Studio. If I create a new project using the template and build it, VS has no problem. I can then save the new project (including built dll) to disk, in a solution folder. The dll runs fine. However, if I go back into the saved project in VS, it complains about project "RGiescke.DllExport.targets" not being found or being on disk, although the file is there.

I guess its a problem with the project file.....

 

Very good tutorial, I like this.

big Thanks. 

 

2011.10.29 20:13:37    2000.01.03 00:00  Expert_NN_1_1 USDJPY,H1: cannot call function 'sum' from dll 'NN 1 DLL.dll' (error 127)

 

 

 

Hi,

 Am getting similar errors. How did you sort it out?... 

2014.03.28 22:16:41.199 2014.03.25 23:59  unresolved import function call

2014.03.28 22:16:41.199 2014.03.25 23:59  Cannot find 'Set2DArray' in 'Testme.dll' 

 
Anybody managed to make ReplaceString function work? all functions are doing there job, except this one, any Ideas?
 

Hello,

Was anybody able to send a structure with string variables inside, to the dll?

I was able to send int, double, float, but for string variables i get this error:

Access violation read to 0x0000007B

Here is my C# structure:

        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct accInfo
        {
            public string broker;
//            public String server;
            public int account;
//            public String user;

            public double balance;
            public Double credit;
//            public String currency;
            public int leverage;
            public int stopout;
            public int stopoutmode;
            public float commission;
            public int lotsize;
            public float minlot;
            public float lotstep;
            public float maxlot;
            public float gmtOffset;

//            public String pair;
            public int digits;
            public int point;
            public int tradeAllowed;
            public int swaptype;
            public float swapbuy;
            public float swapsell;
            public int stoplevel;
        };

And here its the mql4 structure:

   struct accInfo
   {
      string   broker;
//      string   server;
      int      account;
//      string   user;
      
      double   balance;
      double   credit;
//      string   currency;
      int      leverage;
      int      stopout;
      int      stopoutmode;
      float    commission;
      int      lotsize;
      float    minlot;
      float    lotstep;
      float    maxlot;
      float    gmtOffset;
      
//      string   pair;
      int      digits;
      int      point;
      int      tradeAllowed;
      int      swaptype;
      float    swapbuy;
      float    swapsell;
      int      stoplevel;
   };

I have tryed to marshal the string variable inside the structure but MT4 crashes totaly, no error just hangs and crushes in windows.

       [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct accInfo
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string broker;
...

Thank you.

Discussion of article "Exposing C# code to MQL5 using unmanaged exports"
Discussion of article "Exposing C# code to MQL5 using unmanaged exports"
  • www.mql5.com
I also provided several examples on how to marshal MQL5 structures against C# and how to invoke exported DLL functions in MQL5 scripts. - Page 2 - Category: articles, library comments
 

Thank you very much for this article. I've used the ideas here to build this opensource MQL library for C#.

https://github.com/jseparovic/MQL4CSharp

It's still under development and is untested at present, but initial tests show the idea works.

It's very basic in how it sends commands from C#, using a Thread for the C# code to run in, and getters/setters for communication. MQL polls for waiting commands every millisecond, while the C# code can block until the result is written.

Take a look at https://github.com/jseparovic/MQL4CSharp/blob/master/MQL4CSharp/UserDefined/Strategy/MaCrossStrategy.cs for an example of how to implement a strategy in c#.

Cheers,

Jason