Discussion on "How to write a DLL for MQL5 and exchange data in 10 minutes". - page 10

 

That's the thing, the script just kicks out, how can I see the error code after that? Or the next time it's run, can it be read immediately?

In principle, the problem was solved by compiling dll for 64x. Although, after that I got more errors, but it's not important. I just needed to understand how to build and link libraries for c/s++ to mql5 in general. My example works fine now.

 
Will there be an update of the article? Have there been any changes to the dll operation?
 

If you have Studio 2017 and you're looking at these instructions for your old studio and don't know what to do or how to do it, I recommend that you first read this article: https://docs.microsoft.com/ru-ru/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2017

Then, when you've created your dll, following the example from this article and tested it on a client application, read this instruction, starting from point 2, "In MQL5 program it should be described and called like this:". In other words, declare your dll in mt5 as it is described there.

I have solved my problem this way.

 

I'd like a list of type correlations between C++ and MQL in the form of macros.

#define  MQL_STRING wchar_t
 
@Renat Fatkhullin, I need an example on how to resize array and strings in DLL. Should it be done through realloc() or can the passed data not be freed, but just change the pointer to a new data array?
 

Here is my code in Visual Studio 2012 c++. The file main. with cpp extension (main.cpp)

#define  MT4_EXPFUNC __declspec(dllexport) создал макрос чтобы не писать запись __declspec(dllexport)int __stdcall add(int a=0, int b=0)
//__declspec(dllexport)int __stdcall add(int a=0, int b=0)и так пробовал тоже
MT4_EXPFUNC int __cdecl add(int a=0, int b=0)//stdcall данная примитивная функция ничего не делает а просто возвращает значение 18
{return (18);пробовал так return 18;}

Then I created a file with main extension def (main.def), which has a listof exported functions, the code looks like this :

LIBRARY "dllmt42"
EXPORTS
add

Then I imported it into compiler

#import "dllmt42.dll"
int _add(int a=0, int b=0);
#import

No problems in compiling, but when you leave the EA on the chart, I get confused

Unresolved import function call, find '_add' in 'dllmt42.dll'. Total Comander sees the function as well as the compiler itself when dragging the file

Who can help, how to solve the problem with the error, after all there is a file with the extension .def which stores and is responsible for the correct export of functions?


 
Seric29:

Here is my code in Visual Studio 2012 C++. The file main. with cpp extension (main.cpp)

Then I created a file with main extension def (main.def), which has a listof exported functions, the code looks like this :

Then I imported it into compiler

No problems after compilation, but when you leave the EA on the chart, I get confused

Unresolved import function call, find '_add' in 'dllmt42.dll'. Total Comander sees the function as well as the compiler itself when dragging the file

Who can help, how to solve the problem with the error, after all there is a file with .def extension which stores and is responsible for correct export of functions?


extern "C" should be added to both declarations and implementations of exported functions, since this is C++. Otherwise, the input signatures are "plus" and MT (as well as everyone else) will not see them.

 
Maxim Kuznetsov:

extern "C" should be added to both declarations and implementations of exported functions, since C++ is here. Otherwise, input signatures are "plus" and MT (like everyone else) will not see them.

Well, I've added it so

#define  MT4_EXPFUNC extern "C" __declspec(dllexport)
//__declspec(dllexport)int __stdcall add(int a=0, int b=0)
MT4_EXPFUNC int __cdecl add(int a=0, int b=0)//stdcall
{
    return (18);
}

But still the same thing -unresolved import function call, find '_add' in 'dllmt42.dll'... I.e. I need pure C without ++?

 
The .def file is not needed at all. You need to duplicate the functions in the #import section in MQL
 
Roffild:
The .def file is not needed at all. You need to duplicate the functions in the #import section in MQL

Well, yes, and did without it I saw and such, I do not go, well, show me what it is duplicated already point the way?

Reason: