有人問過從MT4到另一個程序進行通信的命名管道,所以這裡是接口和一些示例代碼。這是一個無DLL的解決方案,僅使用MQL4。這假設您已熟悉命名管道。如果你不是,你可以在那裡閱讀
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx

我真的應該把它變成一個圖書館,但我現在沒有時間。如果有人想這樣做,請隨意。

首先是界面:
Inserted Code string PipeNamePrefix=\\\\.\\pipe\\; int BufferSize = 256; #define PIPE_ACCESS_INBOUND 1 #define PIPE_ACCESS_OUTBOUND 2 #define PIPE_ACCESS_DUPLEX 3 #define PIPE_TYPE_BYTE 0 #define PIPE_TYPE_MESSAGE 4 #define PIPE_READMODE_BYTE 0 #define PIPE_READMODE_MESSAGE 2 #define PIPE_WAIT 0 #define PIPE_NOWAIT 1 #define INVALID_HANDLE_VALUE 0xffffffff #define GenericRead 0x80000000 #define GenericWrite 0x40000000 #define OPEN_EXISTING 3 extern string PipeName=MetaTrader; int PipeHandle = INVALID_HANDLE_VALUE; int Buffer#91;64#93;; /4 bytes/int * 64 = 256 #import kernel32.dll int CreateNamedPipeA(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#91;#93;, int bufferSize, int bytesRead#91;#93;, int totalBytesAvail#91;#93;, int bytesLeftThisMessage#91;#93; ); int CreateFileA( string name, int desiredAccess, int SharedMode, int security, int creation, int flags, int templateFile ); int WriteFile( int fileHandle, int buffer#91;#93;, int bytes, int numOfBytes#91;#93;, int overlapped ); int ReadFile( int fileHandle, int buffer#91;#93;, int bytes, int numOfBytes#91;#93;, int overlapped ); int CloseHandle( int fileHandle ); int GetError(); #import To open the pipe as a client, do the following:

插入的代碼FullPipeName = PipeNamePrefix PipeName; if(PipeHandle == INVALID_HANDLE_VALUE){if(WaitNamedPipeA(FullPipeName,1)== 0){//Print(No pipe available available);返回; PipeHandle = CreateFileA(FullPipeName,GenericRead | GenericWrite,0,0,OPEN_EXISTING,0,0);打印(Symbol(),:PipeHandle =,PipeHandle); if(PipeHandle == INVALID_HANDLE_VALUE){打印(管道打開失敗);返回;從管道讀取有點棘手。你不能直接讀入字符串,所以我讀入一個int數組,然後將數組轉換為字符串:
Inserted Code ReadFile( PipeHandle, Buffer, BufferSize, bytesRead, 0 ); message = StringFromBuffer(bytesRead#91;0#93;); string StringFromBuffer(int length) { string message = ; for ( int i = 0; i lt; length; i ) { int c = Buffer#91;i4#93;; int off = i % 4; int shift = 0; if ( off == 1 ) shift = 8; else if ( off == 2 ) shift = 16; else if ( off == 3 ) shift = 24; c = (c gt;gt; shift) 0xff; message = message CharToStr( c ); } return( message ); } And to write to the pipe:
插入代碼CopyToBuffer(orderMessage); result = WriteFile(PipeHandle,Buffer,BufferSize,numOfBytes,0); void CopyToBuffer(string message){for(int i = 0; i lt; 64; i )Buffer#91; i#93; = 0; for(i = 0; i lt; StringLen(message); i ){int off = i%4; int shift = 0; if(off == 1)shift = 8;否則if(off == 2)shift = 16;否則if(off == 3)shift = 24;緩衝器#91; I4#93; | = StringGetChar(message,i)lt; lt;轉移; }}