>>>DLL for sending and receiving a simple text message between 2 MT4 instances

 
Hey :)

I have an EA on an MT4 that needs to send a simple text message to another MT4 with an EA. 
See at the end of my text what I have already tried. It shouldn't be a method where the writing process has to be "opened" and "closed" first, because this leads to errors. I need a dll that will transmit this text message in the simplest possible way. 

In this way:

Sender EA:
#import "C:\msg.dll"
string te;

int start() {
   te = "Information";
   SendText(te);
   return (0);
}
Dll:
SendText() {
}
GetText() {
}
Receiver EA:
#import "C:\msg.dll"
string te;

int start() {
   GetText(te);
   Print("te=", te); // Information
   return (0);
}
I have already tried the Clipboard, voPipeFile and FileMove variants. Due to the constant sending and receiving of the text message with every tick, the first two variants make errors and the FileMove variant (simply constantly renaming a file and letting the file be read) is too slow in terms of speed.

If you know how this can work correctly with a dll, it would be very nice of you if you share your knowledge with me with an answer c:
 
Elfenstein: I have an EA on an MT4 that needs to send a simple text message to another MT4 with an EA. See at the end of my text what I have already tried. It shouldn't be a method where the writing process has to be "opened" and "closed" first, because this leads to errors. I need a dll that will transmit this text message in the simplest possible way. In this way: Sender EA: Dll: Receiver EA: I have already tried the Clipboard, voPipeFile and FileMove variants. Due to the constant sending and receiving of the text message with every tick, the first two variants make errors and the FileMove variant (simply constantly renaming a file and letting the file be read) is too slow in terms of speed. If you know how this can work correctly with a dll, it would be very nice of you if you share your knowledge with me with an answer c:

The simplest way I can think of that does not require DLL (so it can be used on MQL5 VPS), and allows communication between EAs even over the Internet, is to setup a very simple web message queue service, which can run either on the local machine, or on the local network or even on an internet server.

Then with the use of the WebRequest function you can simply interact with the web service to either send messages to the queue or retrieve messages from the queue.

There are many open source web message queue applications available on the internet, some very simple and others that are more complex. Research them to find one that suits your needs or simply code one yourself.

 
Just write/read a file using the FILE_COMMON.
 
Fernando Carreiro #:

The simplest way I can think of that does not require DLL (so it can be used on MQL5 VPS), and allows communication between EAs even over the Internet, is to setup a very simple web message queue service, which can run either on the local machine, or on the local network or even on an internet server.

Then with the use of the WebRequest function you can simply interact with the web service to either send messages to the queue or retrieve messages from the queue.

There are many open source web message queue applications available on the internet, some very simple and others that are more complex. Research them to find one that suits your needs or simply code one yourself.

Thank you for the information, but that's not for me, because I need the fastest method and that only works with RAM :)

 
William Roeder #:
Just write/read a file using the FILE_COMMON.
Yeah I know, thats like the voPipeFile - Method but that is too slow for me. I need the fastest method via RAM. So via Dll would be perfect for me. Clipboard method have to correct speed for me, but it make errors.
 
Elfenstein #: Thank you for the information, but that's not for me, because I need the fastest method and that only works with RAM :)
Elfenstein #: Yeah I know, thats like the voPipeFile - Method but that is too slow for me. I need the fastest method via RAM. So via Dll would be perfect for me. Clipboard method have to correct speed for me, but it make errors.

If both terminals are on the same machine, then use a small RAMDrive with a junction point in the Common directory and then use normal MQL File functionality that William has mentioned. DLL will probably be slower, because of the extra loading overhead, and uses more resources.

However, a simple memory based message queue running as a windows service on the local machine will be just as fast.

 

Another option is to use Named Pipes as they are stored in RAM as long as the message queue does not exceed its ram buffer size (probably around 64KB) at which point it will block.

The example of using the Named Pipes in MetaTrader 4
The example of using the Named Pipes in MetaTrader 4
  • www.mql5.com
Many developers face the same problem - how to get to the trading terminal sandbox without using unsafe DLLs. One of the easiest and safest method is to use standard Named Pipes that work as normal file operations.
 

The following may also be of interest (a quote from someone else's post, see below):

"What you didn´t mention was plain memory blocks, which could be the best for your purpose, cause locking/unlocking is also implemented by Windows and it´s 3-4 times faster than memory mapped files. To deal with such buffers, take a look at the manuals of Microsoft. https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc. You can deal with this functions without the need of any additional DLLs, it can be done entirely in MQL. I use this too in such special environments and its just simple and faster than anything else."

Forum on trading, automated trading systems and testing trading strategies

Data exchange using DLLs vs. DLL-free solutions vs. Memory-mapped files vs. Named pipes vs. Socket communication

Doerk Hilger, 2020.10.01 23:31

Hey,

I did lots of benchmarks with most of the types for data exchange that you mentioned. But its not only about about performance, safety is also very important, because you have to make sure, that there are not two or more processes which try to access and write a file at the same time. This is what you should definetly have in mind. 

Let me give you some hints. 

* MQL file access is not working with shared files, the functions are buggy, don´t use that at all (there is sample code in this forum which I created months ago to demonstrate that)

* Memory mapped files are cool and quick so far, but you have to handle the locking by yourself entirely

* DDE ... no experience in combination with MQL

* Named pipes ... you need a host to setup on, for your purpose probably a little too much overhead

What you didn´t mention was plain memory blocks, which could be the best for your purpose, cause locking/unlocking is also implemented by Windows and it´s 3-4 times faster than memory mapped files. To deal with such buffers, take a look at the manuals of Microsoft. https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc. You can deal with this functions without the need of any additional DLLs, it can be done entirely in MQL. I use this too in such special environments and its just simple and faster than anything else. 

 
Fernando Carreiro #:

If both terminals are on the same machine, then use a small RAMDrive with a junction point in the Common directory and then use normal MQL File functionality that William has mentioned. DLL will probably be slower, because of the extra loading overhead, and uses more resources.

However, a simple memory based message queue running as a windows service on the local machine will be just as fast.

I didn't know the trick with RAMDrive. Thank you very much! I installed with ''ImDisk'' a 4 mb RAMDrive now. But i dont understand how to make a junction point for to use it with FILE_COMMON - flag. Explain it please for me :)
 
Elfenstein #: . But i dont understand how to make a junction point for to use it with FILE_COMMON - flag.

open the command line and enter “mklink /J «junctionName» «path\realDirectory»”