I have been having difficulty getting named pipes to work. I have been hoping to implement a simple idea really and I wish to use named pipes as I don't feel I need to go as advanced as Sockets and I failed miserably with synchronising shared memory. The idea is to monitor a number of MT4 instances and then when I see a trading signal in the prices then I can try and give my trade a slight edge by picking the best priced broker at that time. I want to use named pipes to pump prices into a central C++ application and then the C++ can pick the highest or lowest price broker.
I started with the MSDN examples of named pipes multithreaded server and client and I tried with the help of this thread to replicate the very basics of the client application. I can't get it to work though and I get garbled text through at the server end. However, depending on some slight changes to code often I get the first character coming through correctly. The MSDN examples are below and below them is a snippet of my code which will hopefully be enough info. Please feel free to ask any further questions if not!
I believe if I could replicate the MSDN client in MQL4 then I would be fine to go on from there but I am struggling to even begin debugging this issue at the moment?
#define GENERIC_READ 0x80000000
#define GENERIC_WRITE 0x40000000
#define OPEN_EXISTING 3
int Buffersize = 512;
#import "kernel32.dll"
int CreateNamedPipe(string pipeName, int openMode, int pipeMode, int maxInstances, int outBufferSize, int inBufferSize, int defaultTimeOut, int security );
int WaitNamedPipeA( string lpNamedPipeName, int nTimeOut );
bool PeekNamedPipe( int pipeHandle, int& buffer[], int bufferSize, int& bytesRead[], int& totalBytesAvail[], int& bytesLeftThisMessage[] );
int CreateFileA( string name, int desiredAccess, int SharedMode, int security, int creation, int flags, int templateFile );
int WriteFile( int fileHandle, string buffer, int bytes, int& numOfBytes[], int overlapped );
int ReadFile( int fileHandle, int& buffer[], int bytes, int& numOfBytes[], int overlapped );
int CloseHandle( int fileHandle );
int GetError();
#import
Code:
int init()
{
string Pipename = "\.pipemynamedpipe";
string Testmessage = "T";
int hPipe;
int bytesWritten[1];
bool bsuccess = false;
hPipe = CreateFileA(
Pipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
bsuccess = WriteFile(
hPipe, // pipe handle
Testmessage, // message
StringLen(Testmessage)+1, // message length
bytesWritten, // bytes written
NULL);
return(0);
}
The code for my multithreaded server as I have said is as in the MSDN link above.
Hi guys,
I have been having difficulty getting named pipes to work. I have been hoping to implement a simple idea really and I wish to use named pipes as I don't feel I need to go as advanced as Sockets and I failed miserably with synchronising shared memory. The idea is to monitor a number of MT4 instances and then when I see a trading signal in the prices then I can try and give my trade a slight edge by picking the best priced broker at that time. I want to use named pipes to pump prices into a central C++ application and then the C++ can pick the highest or lowest price broker.
I started with the MSDN examples of named pipes multithreaded server and client and I tried with the help of this thread to replicate the very basics of the client application. I can't get it to work though and I get garbled text through at the server end. However, depending on some slight changes to code often I get the first character coming through correctly. The MSDN examples are below and below them is a snippet of my code which will hopefully be enough info. Please feel free to ask any further questions if not!
I believe if I could replicate the MSDN client in MQL4 then I would be fine to go on from there but I am struggling to even begin debugging this issue at the moment?
MSDN Multithreaded Server
http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
MSDN Client
http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
My .mqh:
My associated .mq4:
int init() { string Pipename = "\.pipemynamedpipe"; string Testmessage = "T"; int hPipe; int bytesWritten[1]; bool bsuccess = false; hPipe = CreateFileA( Pipename, // pipe name GENERIC_READ | // read and write access GENERIC_WRITE, 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe 0, // default attributes NULL); // no template file bsuccess = WriteFile( hPipe, // pipe handle Testmessage, // message StringLen(Testmessage)+1, // message length bytesWritten, // bytes written NULL); return(0); }The code for my multithreaded server as I have said is as in the MSDN link above.
Thanks for any help you can provide!
Mark