Using named pipes - page 2

 
George Wilhelm #:
"access violation" error is killing me too. Did you manage to fix it? I would really appreciate 
What if you use a RAM disk to write and read (an) ordinary file(s)? It's almost as fast as NP and easy to handle.
 
I have already tried that. The thing is, I have a c++ program that receives the asset price from the mql program and send the commands(buy or sell) back to it. Since they both need to access same files(price file and command file), the so called "meta state" error may happen. Inter process communication methods are my only hope.   
 

I have been having this issue too.

i use my own imports (had to trial and error the parameters)

#define INVALID_HANDLE_VALUE -1

#define PIPE_TYPE_MESSAGE 4

#define PIPE_READMODE_MESSAGE 2

#define PIPE_WAIT 0

#define PIPE_ACCESS_DUPLEX 3


#import "kernel32.dll"

int CreateNamedPipeW(string pipeName, int openMode, int pipeMode, int maxInstances, int outBufferSize, int inBufferSize, int defaultTimeOut, int security);

bool ConnectNamedPipe(int hPipe, int overlapped);

bool ReadFile(int hPipe, char& inBuffer[], int NumberOfBytesToRead,  int& bytesRead[], long lpOverlapped);

bool WriteFile(int hPipe, char& sBuffer[], int NumberOfBytesToWrite,  int& bytesWritten[], long lpOverlapped);

bool CloseHandle(int hPipe);

#import


for some unknown reason, this has to be a bug the code worked fine

then i added a line of code after  CreateNamedPipeW and then the code failed on line  CreateNamedPipeW

this of course makes no sense at all, i tried disabling the compiler optimizer and a lot of other stuff

after a lot of trial and error debugging i found placing  CreateNamedPipeW in OnInit solved it (had it in OnTimer first)

i never found a solution online, and a lot of people are facing this problem


so here is the solution :)

 
#import "kernel32.dll"
   int CreateNamedPipeW(string pipeName,ulong openMode,int pipeMode,int maxInstances,int outBufferSize,int inBufferSize,int defaultTimeOut,ulong security);
   
   //int CreateNamedPipeW(string pipeName, long openMode,int pipeMode,long maxInstances,long outBufferSize,long inBufferSize,long defaultTimeOut,long security);
   int PeekNamedPipe(int PipeHandle, int PassAsZero, int PassAsZero2, int PassAsZero3, int & BytesAvailable, int PassAsZero4);
   //int CreateFileW(string Filename, uint AccessMode, uint ShareMode, int PassAsZero, uint CreationMode, uint FlagsAndAttributes, int AlsoPassAsZero);
   long CreateFileW(const string file_name,uint desired_access,uint share_mode,long security_attributes,uint creation_disposition,uint flags_and_attributes,long template_file);
   int CloseHandle(long fileHandle);
   //int ReadFile(int FileHandle, uchar & BufferPtr[], int BufferLength, int & BytesRead, int PassAsZero);
   int ReadFile(long file,const uchar &buffer[],uint number_of_bytes_to_write,uint &number_of_bytes_written,long overlapped);

#import
#import "kernel32.dll"
   int CreateFileW(string lpFileName,uint dwDesiredAccess,uint dwShareMode,uint lpSecurityAttributes,uint dwCreationDisposition,uint dwFlagsAndAttributes,int hTemplateFile);
//   long CreateFileW(const string file_name,uint desired_access,uint share_mode,long security_attributes,uint creation_disposition,uint flags_and_attributes,long template_file);
   int CloseHandle(long fileHandle);
   //int WriteFile(int FileHandle, uchar & Buffer[], int BufferLength, int & BytesWritten, int PassAsZero);
   int WriteFile(long file,const uchar &buffer[],uint number_of_bytes_to_write,uint &number_of_bytes_written[],long overlapped);

#import

try with this...