Download MetaTrader 5
To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
Bohuslav Svancara
12
Bohuslav Svancara 2014.03.11 17:59 

Hello!

I need to update my DLL because of changes in build 610. My old DLL and EA compiled before upgrade to 610 works fine in it. But I am not able to run even the simplest new expert + DLL now.

I am using Visual Studio 2010 and C#. DLL is compiled as 32bit.

Operating system: Windows 7 Prof 64bit

Here is my C# code:

using System.Runtime.InteropServices;
using RGiesecke.DllExport;

namespace C2DLLInvokeTest
{
    public class C2MT4DLLTEST
    {
        [DllExport("C2DLLTest", CallingConvention = CallingConvention.StdCall)]
        public static int C2DLLTest()
        {
            return 123;
        }
    }
}

This is my EA:

#property strict

#import "C2DLLInvokeTest.dll"
int C2DLLTest();
#import      

int OnInit()
  {
   Print("Hello");
   int result=C2DLLTest();
   return(INIT_SUCCEEDED);
  }

And here is my result:

MT4 EA + DLL

What can be a problem?

I am even not able to run the DLLSampleTester.mq4 included in installation. MT4 says: 'DLLSampleTester' is not expert and cannot be executed

I am sitting the whole day on it and I am really desperate.

Help me, please.

Bob

Michael
492
Michael 2014.03.11 19:44  
My first question would be how did you get MT4, originally before the upgrade, to read a managed code DLL?
Michael
492
Michael 2014.03.11 20:08  
Never mind. Just saw this line in code:using RGiesecke.DllExport;
Bohuslav Svancara
12
Bohuslav Svancara 2014.03.12 12:49  
nondisclosure:
Never mind. Just saw this line in code:using RGiesecke.DllExport;

Solved. I re-added the "UnmanagedExports Nuget package" and suddenly it works again.

Happy trading to all!

Michael Sarikas
2979
Michael Sarikas 2014.05.04 09:50  

I have a similar problem using this approach but im calling a string function from c# to mt4 and its not working, it is working for int functions though.

[DllExport("testString", CallingConvention = CallingConvention.StdCall)]
public static string testString()
{
   return ("this is a test string");
}

in the terminal window it returns strange text "??????????g", I have all the correct references and my compiled dll and "RGiesecke.DllExport.Metadata.dll" in the \MQL4\Libraries\ folder, why is this not returning simple text back to mt4?

#import "mytest.dll"
   string testString();
#import
Michael Sarikas
2979
Michael Sarikas 2014.06.08 09:25  

Found it, have to use this way:

 

[return: MarshalAs(UnmanagedType.LPWStr)]

        public static string mystring([MarshalAs(UnmanagedType.LPWStr)] string clearText)

        { ... }
/
To add comments, please log in or register