I need help with import dll - page 3

 
jjc wrote >>

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)'

thanks for the quick response. I think that article is discussing a method that is much more complicated than what i am after at the moment. I just want to do a direct function call from a dll. This seems to have been discussed a fair bit on this forum, but so far i have not been able to find a posting that discribes exactly what the problem is.

error 127 says it cannot call the function from the dll file. it has been mentioned that there could be an issue with the def file, i have tried the suggested correction, but they still dont work. Any ideas?

 
mick:

error 127 says it cannot call the function from the dll file. it has been mentioned that there could be an issue with the def file, i have tried the suggested correction, but they still dont work. Any ideas?

I assume that you've already looked at the experts\samples\DLLSample directory within MT4, and that you're just looking for clarification...


AFAIK you must use a .def file to export functions to things like MT4. The __declspec(dllexport) keyword used in DLLSample is then redundant (at least in VS2008). If you use __declspec(dllexport) without a .def file then your function does get exported from the DLL, but with a name such as "?MyFunction@@YGHXZ". And if you use "extern "C" __declspec(dllexport)" then your function will get exported with a name such as "_MyFunction@0".


In VS2008 you can definitely do the following to get exports to work with MT4. Let's say that you have the following function:

int __stdcall MyFunction() {return 999;}


You then need a simple .def file containing the following:

EXPORTS
	MyFunction


And then you can successfully do the following in MQ4:

#import "MyDll.dll"
   int MyFunction();
#import

...bearing in mind that the function name is case-sensitive.

 

Yeah, I'm getting the same 127 error.


I compile with the .def file. In the case of compiling with and without the .def file, the result is the same error 127. I have done everything in this forum and the error persists. Ugh!!!

 
https://forum.mql4.com/17569
Reason: