DLL Error 127

 

I am receiving the following error message

Cannot call function "xxx" from DLL " xxx" (error 127)

This is a commercial indicator (not EA). I have run the indicator successfully on 2 of my computers with WinXP. A third WinXP computer gives me this error message. The DLL file is in the experts/library folder. I'm not sure what else could be the cause of this error.

Any solution or ideas would be greatly appreciated.

 

SquareRoot:

This is a commercial indicator (not EA).

Why don't you simply ask the author of this Indicator? He is an expert in this field and only he can know what other DLLs might be required or why his DLL might not want to load.
 
On Vista/Win7 don't run MT4 out of the program files (x86) directory
 
WHRoeder:
On Vista/Win7 don't run MT4 out of the program files (x86) directory
I tried from other drive (e:/) still getting that error. Moreover, I used codeblocks to generate the dll, along with the dll a file (.def) is also generated, but even putting them in libraries along with .def gives 127 error ? someone please help.
 

I am still getting that 127 error, someone please help.

I tried copying the dll, the .def both to experts/libaries and moreover, I've installed mt4 on non-root drive(e:)

main.cpp

#define MT4_EXPFUNC __declspec(dllexport)
// a sample exported function

MT4_EXPFUNC double _stdcall Hello( int i)
{
        return( i*10);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}

my.mq4

#import "mt4dll.dll"
double Hello(int);

   int init(){
      Print("Account Number : ",AccountNumber());
   }
   
   
   int start(){
      Print(Hello(89));
   }
 

127 means it can load the dll but cannot find a function with the name "Hello". There is probably some name mangling going on. There exist tools to list the exports of a dll file, use such a tool to find out if this is the case.

Different compilers are doing slightly different things here, mingw/gcc probably behaves slightly different than msvc. All compilers have some means to control this behavior. After making sure that it is indeed a name mangling issue you should consult the manual of your compiler (or the FAQ/support forum/mailing list for this compiler) and find out how to turn off the name mangling or how to control it. Since you did not tell us what compiler you are using we cannot help you, you have to find out yourself. If you really want to become a C programmer then it is absolutely critical that you really understand (or spend a few years learning) all these low level aspects in every detail, how to control them, how to use your tools and how to find out if it worked.

BTW: The .def file does not belong into the experts/libraries folder, it belongs to your source files and contains only instructions for your compiler/linker to tweak the function export behavior. The end result of your efforts should be a dll that works standalone and has all the exports with the correct names in it.

 
7bit:

127 means it can load the dll but cannot find a function with the name "Hello". There is probably some name mangling going on. There exist tools to list the exports of a dll file, use such a tool to find out if this is the case.

Different compilers are doing slightly different things here, mingw/gcc probably behaves slightly different than msvc. All compilers have some means to control this behavior. After making sure that it is indeed a name mangling issue you should consult the manual of your compiler (or the FAQ/support forum/mailing list for this compiler) and find out how to turn off the name mangling or how to control it. Since you did not tell us what compiler you are using we cannot help you, you have to find out yourself. If you really want to become a C programmer then it is absolutely critical that you really understand (or spend a few years learning) all these low level aspects in every detail, how to control them, how to use your tools and how to find out if it worked.

BTW: The .def file does not belong into the experts/libraries folder, it belongs to your source files and contains only instructions for your compiler/linker to tweak the function export behavior. The end result of your efforts should be a dll that works standalone and has all the exports with the correct names in it.

Hi 7 Bit,

this all makes sense to me and I have scoured the web for an answer to my problems for 2 days now. I believe I have everything set correctly but i'm still getting a 127 error similar to above.

I have used the ildasm.exe (available with VS.net) tool to check that the function names in my assembly are not scrambled. I have attached a screenshot showing this.

I have created a dll with C# (VS 2010) using the RGiesecke.DllExport code as described on many websites. The rest of my C# code is below which is very simple.

---

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace AS_dll_drumTOT
{

class UnmanagedExports
{

[DllExport("AddNumDaniel", CallingConvention = CallingConvention.StdCall)]
public static double AddNumDaniel(double num1, double num2)
{
  return num1 + num2 ;
}

}
}

---

I'm using MT4. Dll is in the correct includes folder, I've moved my MT4 installation from the program files directory (as suggested in other posts), may sure permissions are all good and not read only files in the folders.

My MT4 code is below:

--

#property copyright "Cxxxtd"
#property link "fxxxxu"

// function prototypes from dll
#import "AS_dll_drumTOT.dll"
double AddNumDaniel(double num1, double num2);
#import

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red


int init()
{ return (0);
}

int deinit()
{
return(0);
}

int start()
{
for(int i=0; i<3; i++)
{
Print(DoubleToStr(AddNumDaniel(i, 4), 2));
}

return(0);
}

---

PLEASE HELP, I am out of options now.

thanks in advance,

Daniel

 

One more note... I'm basically trying to do an identical thing that's shown in this article:

https://www.mql5.com/en/articles/249

Just with MT4 not MT5. Refer the section 3 & 4 of this article.

thanks

 
n2535904:

Hi 7 Bit,

this all makes sense to me and I have scoured the web for an answer to my problems for 2 days now. I believe I have everything set correctly but i'm still getting a 127 error similar to above.

I have used the ildasm.exe (available with VS.net) tool to check that the function names in my assembly are not scrambled. I have attached a screenshot showing this.

I have created a dll with C# (VS 2010) using the RGiesecke.DllExport code as described on many websites. The rest of my C# code is below which is very simple.

---

<SNIP>

---

PLEASE HELP, I am out of options now.

thanks in advance,

Daniel

Please edit your post . . . .


Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 

Thanks Raptor. My post is edited. I've read hundreds of posts over the past few days. I don't really need assistance with posting, I need help with my coding / compiling dll issue. Hopefully someone else can assist on this.

thanks

 

@n2535904 and anyone else who is struggling to export a Visual Studio C# DLL using RGiesecke's unmanaged exports template, I have created a simple sample DLL in C# with all code available for download that may be used as a template for future projects of this nature. Included is also the code for a Metatrader 4 script that passes data to the C# DLL. Start there and then you can build your more complex code from the basic template.

 Code to Export C# DLL To Metatrader 4

Reason: