FileOpen() and CFilePipe::Open() do not create a pipe

 

Hi all,

I have this simple code trying to write some text on a pipe using 2 different ways for it (using FileOpen() and CFilePipe::Open()):

#include <Files\FilePipe.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   const string filename="\\\\.\\pipe\\pipename";

// first try:
   string function="FileOpen()";
   const int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,function);
      FileClose(filehandle);
      Print(function," OK");
     }
   else
     {
      Print("Operation ",function," failed, error ",GetLastError());
     }

// second try:
   function="CFilePipe::Open()";
   CFilePipe pipe;
   pipe.Open(filename,FILE_WRITE|FILE_BIN);
   if(pipe.Handle()!=INVALID_HANDLE)
     {
      pipe.WriteString(function);
      pipe.Close();
      Print(function," OK");
     }
   else
     {
      Print("Operation ",function," failed, error ",GetLastError());
     }
  }

I always receive this error (Directory does not exist):

2021.05.21 13:50:41.918	example	Operation FileOpen() failed, error 5022
2021.05.21 13:50:41.918	example	Operation CFilePipe::Open() failed, error 5022 
It seems MT5 can't create the pipe.

Please help me to create a pipe using native functions.

Thank you.

 
Felipe Augusto Torres Maggico:

Hi all,

I have this simple code trying to write some text on a pipe using 2 different ways for it (using FileOpen() and CFilePipe::Open()):

I always receive this error (Directory does not exist):

It seems MT5 can't create the pipe.

Please help me to create a pipe using native functions.

Thank you.

You can't. mql5 can only be used as client. To create a pipe you need to use a third party tool or WINAPI.