MT4 DLL Common Errors

The most common error codes when dealing with a MT4 DLL are 126 and 127. Here is what they mean and how to troubleshoot the issue:

Error 126:

Usually this means that your DLL file was not found in the libraries folder.

If the DLL works on your PC but not on another system then it means that you did not link the MFC library as static. To fix the issue go to your project properties and under:

Configuration Properties | General | Use of MFC

Make sure that you have “Use MFC in a Static Library “ selected.
Then rebuild your dll...

Error 127:

By far the most common error, it is due to the def file. You either do not have a def file, it is not linked properly or the function names in your def file are wrong.

Well checking whether you have a def file or not should be easy, check your project folder and make sure it is there. Then open it and make sure the function name match the ones in your MT4 code.

If you get mangled function names such as:

EXPORTS
    _Z11GetSMAArrayP8RateInfoiiPd@16 @ 1
    _Z12GetHighValueP8RateInfoii = _Z12GetHighValueP8RateInfoii@12 @ 2
    _Z12GetHighValueP8RateInfoii@12 @ 3
    _Z13GetCloseValueP8RateInfoii = _Z13GetCloseValueP8RateInfoii@12 @ 4
    _Z13GetCloseValueP8RateInfoii@12 @ 5
    _Z11GetSMAArrayP8RateInfoiiPd = _Z11GetSMAArrayP8RateInfoiiPd@16 @ 6 

Make sure to use the following code:

#ifdef __cplusplus
extern "C" {
#endif
Your code goes here ...
#ifdef __cplusplus
}
#endif

Download the Dev-c++ project from "Writing a basic MT4 Dll" for more info.

Once the above steps have been checked, if you still get error 127, make sure your def file is linked properly.

In visual studio 2008 ( Including Express Version ), go to project, properties, then expand the "linker" group, select "Input" and change the "Module definition File" to be whatever you named your def file. Make sure it has the path and full name of the file - such as .\MyDef.def

In Dev-c++, the def file is created and linked automatically... Unless you manually created it, in which case go to Project Options, Linker parameters and add: --def yourfile.def