EA and DLLs, one more time...

 

I use my own DLL in the EA. When I run it locally, it works. For both, single and optimization.

But if I "stop" test or optimization instead of waiting for normal finish, after that I need to kill metatester64 processes(es), otherwise it will not start any new tests again. This is something I can live with, albeit fat from ideal.

Things get seriously worse when I use local farm. With registry key "/dlls" I can use dlls on farm, but if I "stop" optimization...then farm has to be rebooted as an onlyoption. I can't restart testers in the metatester agent, and even if I kill them manually, agent does not allow to start them again, reboot is the only option. This isn't something one can live with :)

What a hell is wrong here? Any meaningful working workaround? It is RELLY annoying!


Btw, DLL is simple collection of functions, not static variables, no other fancy stuff, so nothing special about initialization/deinitialization.

behavior can be reproduced with simple DLL with single function like:


#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#define _USE_MATH_DEFINES
#include <cstdint>

#define _DLLAPI extern "C" __declspec(dllexport)
_DLLAPI int64_t __stdcall TestFun(const double f) {
  int64_t ret = f > 10;
  return ret;
}


and EA like

//+------------------------------------------------------------------+
//|                                                       testea.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#import "testlib.dll"
long TestFun(const double f);
#import

int OnInit() {
  //---
  return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
  //---
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
  long t = TestFun(1.0);
  double f = 0;
  for (long i = t; i < 100000; i++) {
    f += MathExp((double)i);
  }
  TestFun(f);
  //---
}
//+------------------------------------------------------------------+

EA looks complicated in order to force it go slow, to have change to press "stop" :)

 

I can add that I investigated a bit.

What is happening is that tester is trying to copy DLL to the tester sandbox, but can not overwrite existing copy, because it was never released by the same tester process. And bloody windows does not allow to overwrite open dlls, like any normal unix would.

This problem present for quite a time. To be honest, I have no idea why over this time developers ddn't add to tester 4 lines of code, to try to get a handle of libary, if it is loaded, and attempt to unload, before copying new instanse to sandbox.

Or at least introduce some event for forceful stop, then those things can be handled inside EA properly. 

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
A purchased licensed version allows at least 5 activations. The number of activations is specified by seller. Seller may increase the allowed number of activations