1

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

该函数在 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

4

1 回答 1

0

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

这就是说,文档很清楚,因为New -MQL4.56789的早期设计早在几年前就开始了,补救措施应该从调用接口验证开始。

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


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

设计一个简单的界面 - 如此简单,int aDllCallInterfaceVALIDATOR( <params, ...> );以至于没有一个项目适用于 MQL4/5-side string-s。

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

走简单意味着变得聪明。

(在 New-MQL4.56789 的重新设计中,曾经string-s 开始在技术上被-s 撕裂了很多头发。所以如果没有必要,不必重复这样的痛苦,是吗? )struct{}
:o)

于 2018-04-07T12:33:49.813 回答