How to fix “Unresolved import call: Cannot find Add in TestMe.dll” in MQL4

 

I'm trying to run a function written in C# on MT4 by means of a dll. The dll compiles correctly, however when I try to run it on MT4 i get an unresolved import call cannot find Add in TestMe.dll

Am following a guide on this link https://www.mql5.com/en/articles/249, the dll am using I downloaded it from the page as well. Funny enough when I run the same program using the dll already compiled on the site the code runs fine but when I compile the dll myself using the same code uploaded on the website that's when I start getting the error.

In case you were wondering, I did install the nugget package to enable using RGiesecke.DllExport, also I have the dll located in the mql4 libraries folder and I also enabled "Allow dll imports" in the script common tab.

I don't know if this bit is important but am using Visual Studio Enterprise 2015 and am using .Net Framework 4.5.2

//This is the C# code for the dll

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;

namespace Test
{
    class Test
    {

        private static List<MqlTick> list;

        static Test()
        {
            list = new List<MqlTick>();
        }

        [DllExport("Add", CallingConvention = CallingConvention.StdCall)]
        public static int Add(int left, int right)
        {
            return left + right;
        }

        [DllExport("Sub", CallingConvention = CallingConvention.StdCall)]
        public static int Sub(int left, int right)
        {
            return left - right;
        }

        [DllExport("AddDouble", CallingConvention = CallingConvention.StdCall)]
        public static double AddDouble(double left, double right)
        {
            return left + right;
        }

        [DllExport("AddFloat", CallingConvention = CallingConvention.StdCall)]
        public static float AddFloat(float left, float right)
        {
            return left + right;
        }

    }
}

//This is the MQL4 code for running the dll

#import "TestMe.dll"
   int Add(int left,int right);
   int Sub(int left,int right);
   float AddFloat(float left,float right);
   double AddDouble(double left,double right);
#import
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int i=0; i<3; i++)
     {
      Print(Add(i,600));
      Print(Sub(400,i));
      Print(AddDouble(654.5,i));
      Print(AddFloat(235.5,-i));
     }
  }
//+------------------------------------------------------------------+
I always get an error message Unresolved Import function call Cannot find Add in TestMe.dll, I presume it references "Add" cause that's the first function to be called
Exposing C# code to MQL5 using unmanaged exports
Exposing C# code to MQL5 using unmanaged exports
  • www.mql5.com
I was looking for a long time to find a simple solution that would enable me to use managed mode C# DLLs in MQL5. After reading many articles I was ready to implement C++ wrapper for managed DLL when I came across a brilliant solution that saved me many hours of work. The solution provided a simple example of exporting managed C# code to be...
 

If the above method is hard to explain or correct, I'm completely open to an entirely new approach.

Any help would be much appreciated, thanks.

 
holocast: If the above method is hard to explain or correct, I'm completely open to an entirely new approach.

Any help would be much appreciated, thanks.

  1. Just code it in MT4. No need for DLLs
  2. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
 
William Roeder:
  1. Just code it in MT4. No need for DLLs
  2. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
Thank you for the response. However, Event handling functions won't do the trick. The project am working requires certain functions that is either not existent in mql4 or would be very difficult to implement. That's why I resorted to dll.

The code provided above is not the project am working on, am just using it to test calling dll functions from MT4
 
holocast:
Thank you for the response. However, Event handling functions won't do the trick. The project am working requires certain functions that is either not existent in mql4 or would be very difficult to implement. That's why I resorted to dll.

The code provided above is not the project am working on, am just using it to test calling dll functions from MT4

Check here : https://github.com/vdemydiuk/mtapi

You might find example(s) there how to do what you need
vdemydiuk/mtapi
vdemydiuk/mtapi
  • vdemydiuk
  • github.com
<a href="#mtapi
 
Mladen Rakic:

Check here : https://github.com/vdemydiuk/mtapi

You might find example(s) there how to do what you need
Thanks for the response, but that link is totally unrelated to my question.
 
holocast:
Thank you for the response. However, Event handling functions won't do the trick. The project am working requires certain functions that is either not existent in mql4 or would be very difficult to implement. That's why I resorted to dll.

The code provided above is not the project am working on, am just using it to test calling dll functions from MT4

There is not much that can't be done in mql. The main advantages of other languages is availability of libraries.

Anyway, you should think about switching to MT5/mql5 which allow to work directly with C# DLL now. Example.

 
Alain Verleyen:

There is not much that can't be done in mql. The main advantages of other languages is availability of libraries.

Anyway, you should think about switching to MT5/mql5 which allow to work directly with C# DLL now. Example.

Yes true the libraries are what makes the difference.

Switching to MT5 would require a lot of conversions for all the programs that have already been developed for MT4. That in itself is a herculean task.

But does this mean that nothing can be done to make MT4 run the functions in the above dll?
 
holocast:
Yes true the libraries are what makes the difference.

Switching to MT5 would require a lot of conversions for all the programs that have already been developed for MT4. That in itself is a herculean task.

But does this mean that nothing can be done to make MT4 run the functions in the above dll?
Like I mentioned earlier when I download the already compiled dll from the link everything works fine, but when I copy the code and compile it myself, that's when I start to get this error.

This leads me to believe that the problem probably started from compilation, I just can't seem to pinpoint it
 
holocast:

I'm trying to run a function written in C# on MT4 by means of a dll. The dll compiles correctly, however when I try to run it on MT4 i get an unresolved import call cannot find Add in TestMe.dll

Am following a guide on this link https://www.mql5.com/en/articles/249, the dll am using I downloaded it from the page as well. Funny enough when I run the same program using the dll already compiled on the site the code runs fine but when I compile the dll myself using the same code uploaded on the website that's when I start getting the error.

In case you were wondering, I did install the nugget package to enable using RGiesecke.DllExport, also I have the dll located in the mql4 libraries folder and I also enabled "Allow dll imports" in the script common tab.

I don't know if this bit is important but am using Visual Studio Enterprise 2015 and am using .Net Framework 4.5.2

//This is the C# code for the dll

//This is the MQL4 code for running the dll

this problem is very simple.

MT4-> https://c.mql5.com/3/256/Ekran_Alznt9sy.JPG

MT5->https://c.mql5.com/3/256/MT5DLL.JPG


https://www.mql5.com/en/forum/293517#comment_9811172

MT4 DLL Not Support
MT4 DLL Not Support
  • 2018.12.04
  • www.mql5.com
MT4 also developed by its own company does not work why the DLL. Script under DLLSampleTester.mq4...
 
Make sure the platform target is set to x86, if it's set to "Any CPU" MT4 will load the dll but won't find any function within it, it'll only throw an error "Cannot load... " if the platform target is set to x64
Reason: