文章 "使用非托管导出将 C# 代码运用到 MQL5"

 

新文章 使用非托管导出将 C# 代码运用到 MQL5已发布:

在本文中,我介绍了在 MQL5 代码和托管 C# 代码之间进行互动的不同方法。我还提供了几个例子来说明如何针对 C# 封送 MQL5 结构以及如何在 MQL5 脚本中调用导出的 DLL 函数。我相信提供的例子能用作以后研究用托管代码编写 DLL 的基础。本文也为 MetaTrader 使用已经在 C# 中实施了的多个库打开了大门。

图 2. COM 互操作模型

作者:investeo

 

我是64的win 8

用vs2013编译的

但是 可以加载了  但是  出现了 unresolved import function call

如何解决?

2014.03.05 20:39:59.220 UnmanagedExportsDLLExample1 (XAUUSD,H1) unresolved import function call

2014.03.05 20:39:59.220 UnmanagedExportsDLLExample1 (XAUUSD,H1) Cannot find 'Add' in 'Testme.dll'

 

方法一:

我是64的win 7,vs2012 C#。下载楼主的 testme.zip模板文件。

中间提示了几个错误(路径不对,文件丢失等之类的),已经解决了。

但最后,还是出现和和楼上同样的问题。不知道现在解决了没有?什么方法解决的。



方法二:

NuGet 安装的 RGiesecke包.

https://www.nuget.org/packages/UnmanagedExports/1.2.6

2013年11年最新的版本,提示

错误    2    C:\Users\Administrator\AppData\Local\Temp\tmp8B24\dllTest.il(58) : error : syntax error at token '{' in:   {
    dllTest



Unmanaged Exports (DllExport for .Net)
Unmanaged Exports (DllExport for .Net)
  • www.nuget.org
A set of compile-time libraries (nothing to deploy) and a build task that enable you to export functions from managed code to native applications. That means, you can create plugins in a managed language like C# or F# for native applications that only have a C-Api (like Notepad++). The nuget package is all you need. Just mark your methods with [DllExport] and build for x86, x64 or ia64. Hints: - You have to set your platform target to either x86, ia64 or x64. AnyCPU assemblies cannot export functions. - The export name defaults to the method name and the calling convention to stdcall. If that's all what you want, you can just use [DllExport] without parameters. - You cannot put your exports in generic types or export generic methods. (The CLR wouldn't know what type parameters to use)
 

错误    2    C:\Users\Administrator\AppData\Local\Temp\tmp8B24\dllTest.il(58) : error : syntax error at token '{' in:   { dllTest

这种错误会出现在中文版的系统中,原因是UnmanageExports在生成IL文件时,一些注释被生成为中文导致UnmanageExports无法正常工作。这个问题是不会在日文和英文的操作系统上出现的,解决方案是有的,你可以把你得操作系统换成英文的~

但是这样就太麻烦了对吧,这里就需要拿出小狐狸的东西来修复一下咯!

在下面的地址中下载小狐狸提供的Unmanaged Exports修复版本

https://www.noisyfox.cn/397.html

http://www.magecorn.com/p/280.shtml 

详情请看上面两篇文章 

 

    楼主上面的代码怎么一直运行不了的呢

    2017.04.28 23:48:08.774 Cannot find 'Add' in 'Testme.dll'

不管怎么按你们的方法写C# DLL,都没用的,我用其他软件测了这方法也没问题,就MT4这里不行,能不能发一个新的一点版本?
原因: