cannot call function 'myfunction' from dll 'myfunction.dll' (error127)

 

Hello Guys,

I am having problems using a dll function in mt4. I have this function in C that I tested in another C console application program. I exported like

#include<windows.h>
#define N 400
extern "C" __declspec(dllexport) double myfunctiondll(double rates[N]){  return rates[0]+0.5*rates[20];}

in my C console application I call it like this with no problems. I place the myfunctiondll.dll and myfunctiondll.lib in the /Debug/ folder were the executable is and in the linker option I add the dependancies.

extern "C" __declspec(dllimport) double myfunctiondll(double rates[N]);

However in mt4 I get the error cannot call function 'myfunction' from dll 'myfunction.dll' (error127) . I used in this EA code:

#include <stdlib.mqh>
#define N 400

#import "myfunctiondll.dll"
double myfunctiondll(double rates[N]);
#import

int n;
int i;
double to;
double rates[N];
double old_ask;
double old_bid;
double new_ask;
double new_bid;

int init(){
     n=40;
     i=0;
   return(0);
  }

int deinit(){
   return(0);
  }

int start()
  {
   ArrayInitialize(r,0.0);
   old_ask = Ask;
   old_bid = Bid;
   while(i<n+1){
      new_ask=Ask;
      new_bid=Bid;
      if(new_ask!=old_ask || new_bid!=old_bid){
         rates[i]=new_bid;
         rates[i+1]=new_ask;
         old_ask=new_ask;
         old_bid=new_bid;
         Comment("Bid=",DoubleToStr(rates[i],6)," Ask=",DoubleToStr(rates[i+1],6)," i=",i);
         i++;
      } else RefreshRates();
   }
   Print(myfunctiondll(rates));
  
   return(0);
  }
//+---------------

I put myfunctionddl.dll and myfunctiondll.lib inside ../experts/libraries/

 

I haven't used dlls but according to these : https://www.mql5.com/en/forum/106871/page2 and https://docs.mql4.com/runtime/imports I think you should export with _stdcall instead of __declspec

Reason: