In mql5 pipes connection also works only in Common Folder rules?

 

Hi Everybody.

In mql5 pipes connection also works only in Common Folder rules? 

I am trying to connect with a pipe connection that works perfectly in mt4 but in mt5 I always receive Access Violation...

I am using my old program created in Visual Studio that I connect via mt4 between pipes...In mt4 works fine.

In this app side I am using this simple line to connect

res = CallNamedPipe("\\.\pipe\teste", textOut(0), command.Length + 1, textInArray(0), 255, cbRead, PIPE_NOWAIT)

In the mt5 script I can print the message "Conected PipeServer" but after this in the line bool fSuccess = ReadFile(hPipe I am receiving the error.

I already question about it but many years ago but I neved thought about the Common Folder rules.

void OnStart()
  {
    string PipeName = "\\\\.\\pipe\\teste";
    int    PipeMode = PIPE_TYPE_BYTE  | PIPE_READMODE_BYTE  | PIPE_WAIT;
    hPipe      = CreateNamedPipeW(PipeName, PIPE_ACCESS_DUPLEX, PipeMode, PIPE_UNLIMITED_INSTANCES, 255, 255, 1000, NULL);
    BufferSize = PIPE_BUFFER_SIZE;
    if (hPipe == INVALID_HANDLE_VALUE)
    {
        err = GetLastError();
        //Print("error(", err1, "): ", ErrorDescription(err1));
        Print("CreateNamedPipe failed");
    }
    else
    {
        Print("Named Pipe was created");
    }
    while (true)
    {
        Print("standy by");
      
        bool fConnected = ConnectNamedPipe(hPipe, NULL) != 0;
        Print("Conectou PipeServer");
        if (fConnected)
        {
            int  inBuffer[255];
            int  bytesRead[1];
            bool fSuccess = ReadFile(hPipe, inBuffer, 4 * ArraySize(inBuffer), bytesRead, NULL) != 0;
            if (!fSuccess || (bytesRead[0] == 0))
            {
                break;
            }
            inString = "";
            for (int i = 0; i < bytesRead[0]; i++)
            {
                inString = inString + CharToString((inBuffer[i / 4] >> ((i & 3) * 8)) & 0xff);
            }
            Print("instring= " + inString);
            break;
        }
     }
  }

and here the error

Access violation at 0x00007FF8D8E0AE5F write to 0x0000020D00000000
crash -->  00007FF8D8E0AE5F 49C70603010000    mov        qword [r14], 0x103
00007FF8D8E0AE66 418B4610          mov        eax, [r14+0x10]
00007FF8D8E0AE71 418B4614          mov        eax, [r14+0x14]
00007FF8D8E0AE75 89842484000000    mov        [rsp+0x84], eax
00007FF8D8E0AE7C 498B5618          mov        rdx, [r14+0x18]
00007FF8D8E0AE80 F6C201            test       dl, 0x1
Documentação sobre MQL5: Funções Comuns / Print
Documentação sobre MQL5: Funções Comuns / Print
  • www.mql5.com
Print - Funções Comuns - Referência MQL5 - Referência sobre algorítimo/automatização de negociação na linguagem para MetaTrader 5
 

If I use this code in my app side:

 Dim server As String = "."
        Dim pipeClient As New NamedPipeClientStream(server, "pipe\teste", PipeDirection.InOut, PipeOptions.None)

the connection doesn't even happen. Probably because is a .net vs kernel32...I dont know...In mt4 works fine...

 

I read in other forum that the problem is about 64bits version. 

https://mqldiscussions.com/t/mql5-asynchronous-named-pipes/888

I am using windows10 64bit

So back to MT4 again...

MQL5 Asynchronous named pipes?
MQL5 Asynchronous named pipes?
  • 2019.11.11
  • mrakey (Mirelle Rake)
  • mqldiscussions.com
I´m trying to integrate MT5 with an external Named Pipe Server application written in C# through named pipes. The problem is the app requires a Asyncronous named pipe, and I can´t find a way to connect to it...
 

Using this codes

long  ReadFile(long fileHandle,uchar &buffer[],long bytes,long &numOfBytes,long overlapped);

and

            uchar  inBuffer[255]={0};
            long number_of_bytes_to_read=255;
            long number_of_bytes_read=0;
            
            Print("00");
            
            int succes = ReadFile( hPipe, inBuffer,number_of_bytes_to_read,number_of_bytes_read,NULL);

It dont generate the error Access Violation but  I never receive any byte and GetLastError is zero too.


I am using this code in the VisualStudio

 command = "teste"
        Dim res As Integer = 0
        Dim cbRead As Integer
        Dim textInLength As Integer
        Dim textOut() As Byte
        Dim textIn As String
        Dim textInArray() As Byte
        pipeName_ToMT4 = "\\.\pipe\teste"
        'La no script mql ele vai analisar o comando e nos responder. Abaixo, ele envia o comando e lê a resposta.
        textOut = System.Text.Encoding.Default.GetBytes(command)
        textInLength = 255
        ReDim textInArray(textInLength)
        res = CallNamedPipe(pipeName_ToMT4, textOut(0), command.Length + 1, textInArray(0), 255, cbRead, PIPE_NOWAIT)
 
In the Visual Studio side I am receiving the error 87...I need go further...
Razão: