MQLとC#について

はじめに

まあ,うまくいかないわけですよ。
最初実は,

fx-dollaryen.seesaa.net

こっちの記事見ながらやってたんですが,
うまくいかないわけですよ。

問題点

nugetからUnmanaged Exportsを利用する際にそのままやると2つエラーがでます。

  1. error : syntax error at token '{' in:
  2. error : Microsoft.Build.Utilities.ToolLocationHelper could not find ildasm.exe.

です。
この2つは別々の原因によって発生しているので,原因を切り分けて進めていく必要がありました。

環境

Windows 10 20H2
Microsoft Visual Studio Express 2017 for Windows Desktop 15.9.29

error : syntax error at token '{' in:について

これはマルチバイト文字に関するエラーのようで,ネットの記事をみると,Unicode対応ではないプログラムの言語をENにしてねってありますが,自分の環境ではエラー吐いたままでした。
なので,そんなことよりパソコンの言語をEN(US)とかに変えたところエラー解消しました。

f:id:iinebot:20201208200459p:plain

error : Microsoft.Build.Utilities.ToolLocationHelper could not find ildasm.exe.について

なんかよくわかんないですが,何かが違って実行ファイルが見つからないようです。
これは,nugetライブラリの作成が古いことが原因のようで,UnmanagedExports.Repackってやつをnugetからインスコすると解決しました。

f:id:iinebot:20201208200441p:plain

MQL4側の処理

紆余曲折あってDLLの名前を考えている余裕もなかったので・・・。

//+------------------------------------------------------------------+
//|                                                      dllTest.mq4 |
//|                                        Copyright 2020, InvestorX |
//|                                  https://iinebot.hatenablog.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, InvestorX"
#property link      "https://iinebot.hatenablog.com/"
#property version   "1.00"
#property strict
#property indicator_chart_window

#import "ClassLibrary4.dll"
   int  Plus(int left, int right);
#import
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

   
   Print(IntegerToString(Plus(1,2)));
//--- return value of prev_calculated for next call
   return(rates_total);
  }

ひたすら3とPrintし続けるあふぉなインジが完成しました。
f:id:iinebot:20201208201000p:plain

おわりに

ロンドさんの記事にコメントしているKさんの言ってるように
public static int

public unsafe static int
に変更しプロパティでアンマネージドをクリック
はしといた方が良いかもしれません(未検証)。

目的は果たせたのでとりあえず終了!