1

I am trying to make a call to the function Train() from an #import-ed DLL.

The function is there, in the DLL-file and I have confirmed it being exported through a DLL-viewer.

I have tried the following code in MQL5 for calling DLL-functions:

#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

In C file I have the function declaration as:

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
)

And

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
)

I am getting the following error after calling the indicator:

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

I have checked the viewer and the DLL have the function called Train available in it.

See the image:
enter image description here

Here is the DLL: NNModel.dll

James Z
  • 12,209
  • 10
  • 24
  • 44
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139

1 Answers1

0

A novice may get surprised that a string in MQL4/5 is not a string

This said, the documentation is clear in this since early design creeps of New-MQL4.56789 started years ago, the remedy shall start with call-interface validation.

A reverse-engineering hunt for a just temporarily valid actual dirty #pragma-decorated struct{}-layout is possible, but permanently risky and very inefficient in production grade software engineering ...


The best next step - keep the safety of the C-side best practices:

Design a trivial interface - as simple as int aDllCallInterfaceVALIDATOR( <params, ...> ); such that none of items works with MQL4/5-side string-s.

Once your call-interface code-integration works well for all parameters with your DLL-side intents and can also return reasonable data / results back to the hands of MQL4/5-code, return back to the intended functionality.

Going simple means going smart.

( Had many hairs torn off once string-s started to be technically struct{}-s in the New-MQL4.56789 still creeping magma of re-engineering. So need not repeat such pain if it is not necessary, is it?
:o) )

user3666197
  • 1
  • 6
  • 50
  • 92
  • I understand. But your answer is bit tricky to understand by me. I don't know what exactly it means. Can you help me in making adjustments to my code what I have mentioned in the question. If you need anything else then let me know I will share. – Jaffer Wilson Apr 07 '18 at 13:07
  • Please Michael, let me know what you mean with some short example. I will accept your answer when I understand what you wanted to convey me. – Jaffer Wilson Apr 13 '18 at 05:42