我的最终目标是能够使用多个MT45平台来提供用C#编写的自定义应用程序。
插入代码MT5 | | \MT5 - 黑盒子C#programlt; --- MT5\ | | MT5
目前,黑匣子什么也没做。我正在努力进行沟通。
我有Client.cs和Server.cs成功地相互交谈。当我将PipeServer输出到.dll并尝试在MT5中加载时,我收到错误,在'PipeServer.dll'中找不到'SendString'。我已经尝试了所有我能想到的东西。我已经阅读了大量的在线文章,我仍在圈子里。
PipeServer的C#代码:(不介意所有注释。它只是让它更容易在dll和exe之间来回切换)
使用System插入代码;使用System.Collections.Generic;使用System.Linq;使用System.Text;使用System.IO.Pipes;使用System.IO;使用System.Diagnostics;使用System.Runtime.InteropServices;使用RGiesecke.DllExport; namespace PipeServer {public class Server {//static void Main(string#91;#93; args)#91; DllExport(SendString,CallingConvention = CallingConvention.StdCall)#93; public static void SendString(string args){using(NamedPipeServerStream pipeServer = new NamedPipeServerStream(testpipe,PipeDirection.InOut)){//Console.WriteLine(NatatedPipeServerStream对象已创建。);/等待客户端连接//Console.Write(等待客户端连接...); pipeServer.WaitForConnection();/Console.WriteLine(客户连接。);/bool Disconnect = false;尝试{//读取用户输入并将其发送到客户端进程。 using(StreamWriter sw = new StreamWriter(pipeServer)){//string temp;/while(pipeServer.IsConnected!Disconnect)//{sw.AutoFlush = true;/Console.Write(输入文字:);/temp = Console.ReadLine();/if(temp == exit)Disconnect = true;/Disconnect = true; sw.WriteLine(参数);/}}}/捕获管道被破坏或断开时引发的IOException。 ch(IOException e){Console.WriteLine(ERROR:{0},e.Message); }}}}}
PipeClient的C#代码:
使用System插入代码;使用System.Collections.Generic;使用System.Linq;使用System.Text;使用System.IO.Pipes;使用System.IO;使用System.Diagnostics; namespace PipeClient {public class Client {static void Main(string#91;#93; args){using(NamedPipeClientStream pipeClient = new NamedPipeClientStream(。,testpipe,PipeDirection.InOut)){//连接到管道或等到管道是可用的。 Console.Write(试图连接管道......); pipeClient.Connect(); Console.WriteLine(连接到管道。); Console.WriteLine(当前有{0}管道服务器实例打开。,pipeClient.NumberOfServerInstances); while(pipeClient.IsConnected){using(StreamReader sr = new StreamReader(pipeClient)){//将读取的文本显示到控制台字符串temp; while((temp = sr.ReadLine())!= ){Console.WriteLine(从服务器接收:{0},temp); Console.Write(按Enter继续......);到Console.ReadLine(); }}}
EA脚本的MQL5代码:
插入的代码// --------------------------------------------- --------------------- /| TestPipeServer.mq5 |/|版权所有,无|/| |/ ----------------------------------------------- ------------------- /#property script_show_inputs #import PipeServer.dll static void SendString(string args); #import/ --------------------------------------------- --------------------- /|脚本程序启动功能|/ ----------------------------------------------- ------------------- void OnStart(){打印(测试加载正确); SendString(测试);/如果我注释掉这个函数调用,脚本可以工作}/ --------------------------------- ---------------------------------
测试C#lt; - C#在没有任何性能调整的情况下提供超过165,000个秒/秒的吞吐量。这是我想要使用DLL解决方案的主要原因之一。此外,在C#中开发的限制要少得多。我确实理解有使用本机MQL5代码的方法,但这不是我追求的路径。
所以我的整体问题是如何正确调用我的SendString(字符串someParameter)?
目前我发送的数据类型无关紧要。它可以是int,double或string。我只想让功能正常运行。
任何帮助或建议将不胜感激,所以我可以停止
谢谢,
贾森