I need help with import dll - page 2

 
marshall318:
phy:

Does your DLL export the function named Add ?


I renamed the function from 'Add' to 'AddTwo', I still got the error 127. The following are the files generated from Matlab mcc command:

AddTwo.c, AddTwo.ctf, AddTwo.exports, AddTwo.h, AddTwo_mcc_component_data.c, AddTwo.dll, AddTwo.exp, AddTwo.lib

 #import "AddTwo.dll"
     int AddTwo( int a, int b);
#import
 
int start()
  {
//----
  
int x = 5;
int y = 10;
 
     Print(" 2 + 3 = ", AddTwo( 2, 3));
     Print(" x + y = ", AddTwo( x, y));
    
   return(0);
  }
I read some threads about error 127, the possible solution is to put a definition file in the import. but I don't know what a def file looks like.
 
127 sounds familiar, are you sure you have permissions set in your MT4 to allow DLL calls ?


Def file in C++ looks like this. See the /experts/samples for a def file

Library is the dll name, exports are the names of the functions MT4 will call

--- def file below -----

LIBRARY AddTwo

EXPORTS AddTwo
 

The setting is right: call of dll is permitted.

Could you pls read the thread: 'Error 127 calling a dll function ? Please help.', they came up with a solution for error 127, but I do not understand how they solved it. def file and _stdcall ? What is it like in MQL4 coding?

Thanks a lot.

 
https://forum.mql4.com/9660

"Exported functions for MT4 created in Visual must be declared as _stdcall, not as _cdecl, which is the standard-declaration of functions in Visual !"

This is in the source code for the DLL, specifying something about the calling conventions for MT4 to "call" the function in the DLL They are standard calls and not Microsoft proprietary calls.


"I have created a .def file and put it into experts\libraries, but the problem persists. what am i doing wrong? should I put it somewhere else? or is the format wrong?"

The def file is used by the linker during compilation of the DLL. I don't know the details, but it tells the linker? compiler? DLL code? what functions will be available for calling.

---

You are using MatLab, I have no idea about the detail of that software. Maybe someone else does. My experience is with C++. But MT4 needs "proper" DLL to work with.

Summarizing, the calls into the DLL must be "standard calls" not "decorated" in some Microsoft way, the DLL needs to explicitly be told about the exported functions -- the DEF file, the DLL has to be in a folder accessible by MT4, and MT4 is limited in the data types it can receive from the DLL
 
phy:

'Error 127 calling a dll function ? Please help.'

"Exported functions for MT4 created in Visual must be declared as _stdcall, not as _cdecl, which is the standard-declaration of functions in Visual !"

This is in the source code for the DLL, specifying something about the calling conventions for MT4 to "call" the function in the DLL They are standard calls and not Microsoft proprietary calls.


"I have created a .def file and put it into experts\libraries, but the problem persists. what am i doing wrong? should I put it somewhere else? or is the format wrong?"

The def file is used by the linker during compilation of the DLL. I don't know the details, but it tells the linker? compiler? DLL code? what functions will be available for calling.

---

You are using MatLab, I have no idea about the detail of that software. Maybe someone else does. My experience is with C++. But MT4 needs "proper" DLL to work with.

Summarizing, the calls into the DLL must be "standard calls" not "decorated" in some Microsoft way, the DLL needs to explicitly be told about the exported functions -- the DEF file, the DLL has to be in a folder accessible by MT4, and MT4 is limited in the data types it can receive from the DLL


I guess I have to find someone with Matlab experience. Thank you very much.
 
Try asking your question on the Russian Forum...

https://www.mql4.com/ru/search/MATLAB

----

What sort of tool are you making? Curious, now...
 
phy:

Try asking your question on the Russian Forum...

https://www.mql4.com/ru/search/MATLAB

----

What sort of tool are you making? Curious, now...



I am building NNs to predict future trend like what Better did in the Championship. Have you got a money-making EA now? If not, try to make one for yourself. It won't be very difficult for you. Good luck! Thanks again for your help.
 
marshall318:
phy:

Try asking your question on the Russian Forum...

https://www.mql4.com/ru/search/MATLAB

----

What sort of tool are you making? Curious, now...



I am building NNs to predict future trend like what Better did in the Championship. Have you got a money-making EA now? If not, try to make one for yourself. It won't be very difficult for you. Good luck! Thanks again for your help.

Hi,


Have you had any luck getting this working? I am getting the same error.

 
Hi, has anyone had any luck in resolving the problem of getting error 127 when trying to import dll's made from matlab?
 
mick:
Hi, has anyone had any luck in resolving the problem of getting error 127 when trying to import dll's made from matlab?

Not tried it myself, but one of the sticky topics at the top of the forum seems to be on this subject: 'New article: Interaction between MеtaTrader 4 and MATLAB Engine (Virtual MATLAB Machine)'

Reason: