【问题标题】:Cannot find function in DLL using MQL5使用 MQL5 在 DLL 中找不到函数
【发布时间】:2018-04-07 11:09:12
【问题描述】:

我正在尝试从 #import-ed DLL 调用函数 Train()

该函数在 DLL 文件中,我已确认它是通过 DLL 查看器导出的。

我在 MQL5 中尝试了以下代码来调用 DLL 函数:

#import "NNModel.dll"
string Train(
   double &inpTrain[], // Input training data (1D array carrying 2D data, old first)
   double &outTarget[],// Output target data for training (2D data as 1D array, oldest 1st)
   double &outTrain[], // Output 1D array to hold net outputs from training
   int     ntr,        // # of training sets
   int     UEW,        // Use Ext. Weights for initialization (1=use extInitWt, 0=use rnd)
   double &extInitWt[],// Input 1D array to hold 3D array of external initial weights
   double &trainedWt[],// Output 1D array to hold 3D array of trained weights
   int     numLayers,  // # of layers including input, hidden and output
   int    &lSz[],      // # of neurons in layers. lSz[0] is # of net inputs
   int     AFT,        // Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
   int     OAF,        // 1 enables activation function for output layer; 0 disables
   int     nep,        // Max # of training epochs
   double  maxMSE      // Max MSE; training stops once maxMSE is reached
   );

string Test(
   double &inpTest[],  // Input test data (2D data as 1D array, oldest first)
   double &outTest[],  // Output 1D array to hold net outputs from training (oldest first)
   int     ntt,        // # of test sets
   double &extInitWt[],// Input 1D array to hold 3D array of external initial weights
   int     numLayers,  // # of layers including input, hidden and output
   int    &lSz[],      // # of neurons in layers. lSz[0] is # of net inputs
   int     AFT,        // Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
   int     OAF         // 1 enables activation function for output layer; 0 disables
   );
#import

C 文件中,函数声明为:

MT5_EXPFUNC char* __stdcall Train(
const double* inpTrain, // Input training data (2D data as 1D array, oldest first)
const double* outTarget,// Output target data for training (2D data as 1D array, oldest first)
      double* outTrain, // Output 1D array to hold net outputs from training
const int     ntr,      // # of training sets
const int     UEW,      // Use External Weights for initialization (1=use extInitWt, 0=use rnd)
const double* extInitWt,// Input 1D array to hold 3D array of external initial weights
      double* trainedWt,// Output 1D array to hold 3D array of trained weights
const int     numLayers,// # of net layers including input, hidden and output
const int*    lSz,      // # of neurons in layers. lSz[0] is # of net inputs (nin)
const int     AFT,      // Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
const int     OAF,      // 1 enables activation function for output layer neurons; 0 disables
const int     nep,      // Max # of training epochs
const double  maxMSE    // Max MSE; training stops once maxMSE is reached
)

MT5_EXPFUNC char* __stdcall Test(
const double* inpTest,  // Input test data (2D data as 1D array, oldest first)
      double* outTest,  // Net outputs from testing
const int     ntt,      // # of test sets
const double* extInitWt,// Input 1D array to hold 3D array of external initial weights
const int     numLayers,// # of net layers including input, hidden and output
const int*    lSz,      // # of neurons in layers. lSz[0] is # of net inputs (nin)
const int     AFT,      // Type of neuron activation function (0:sigm, 1:tanh, 2:x/(1+x))
const int     OAF       // 1 enables activation function for output layer neurons; 0 disables
)

调用指标后出现以下错误:

Cannot find 'Train' in 'NNModel.dll'
unresolved import function call

我检查了查看器,并且 DLL 中有一个名为 Train 的函数。

看图:

这里是 DLL:NNModel.dll

【问题讨论】:

    标签: c dll mql5 metatrader5


    【解决方案1】:

    新手可能会惊讶于 MQL4/5 中的 string 不是 string

    这就是说,the documentation is clear in this 自从 New-MQL4.56789 的早期设计开始多年前,补救措施应从调用接口验证开始。

    逆向工程寻找一个只是暂时有效的实际脏 #pragma-decorated struct{}-layout 是可能的,但在生产级软件工程中永久存在风险且效率非常低...


    最好的下一步——保持 C 端最佳实践的安全性:

    设计一个简单的界面 - 就像 int aDllCallInterfaceVALIDATOR( <params, ...> ); 这样简单,这样所有项目都不能与 MQL4/5 端 string-s 一起使用。

    一旦您的调用接口代码集成对您的 DLL 端意图的所有参数都有效,并且还可以将合理的数据/结果返回到 MQL4/5 代码的手中,返回到预期的功能。

    简单意味着聪明。

    ( 曾经有很多头发被扯掉了 string-s 在新的 MQL4.56789 中开始在技术上是 struct{}-s 仍然匍匐的岩浆重新-工程。所以如果没有必要,不必重复这种痛苦,是吗?
    :o))

    【讨论】:

    • 我明白了。但是我的回答有点难以理解。我不知道它到底是什么意思。你能帮我调整我在问题中提到的代码吗?如果您需要其他任何内容,请告诉我,我会分享。
    • 请迈克尔,用一些简短的例子告诉我你的意思。当我明白你想传达给我的内容时,我会接受你的回答。
    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多