Problems running EA with custom DLL in Strategy Tester. Am I doing something wrong, or is it a MT5 bug?




I'm testing an EA in Strategy Tester (ST)  that uses a custom DLL. If I stop the test before the test ends (either from Strategy Tester or MT5), I'm unable to start the test again unless I close the ST window first -- ie. clicking the "start" button in MT5's ST toolbar while the ST window is open generates an error:  "file Libraries\TestDLL.dll write error [32]"  (see fig01)

Version: 5.00 build 2280 64-bit


It seems that error 32 is "The process cannot access the file because it is being used by another process", and for some reason I don't know, the DLL is not unloaded after I stop the test (see fig02). It seems that for this reason, the testing system is unable to copy the DLL from the "terminal_dir\MQL5\Libraries" folder to the working folder (i.e. "<AppData>\Roaming\MetaQuotes\Tester\3593432D98AE63F59A12C30CEE53D6DA\Agent-\MQL5\Libraries"). I browsed this folder and tried to delete the DLL file (as a test), and I was unable to do it (fig03).

I've noticed that ST unloads the DLL if the test finishes by itself (ie. when the test reaches the end date set in the test configuration).

I raised this issue because I'm developing a tool to use in the ST (which uses a custom DLL), and requiring the user to close the ST window everytime to start again is just annoying. 

Here is the test EA code:

//|                                                   TestExpert.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                    |
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"

#import "TestDLL.dll"
void test (int& x);

//| Expert initialization function                                   |
int OnInit()
   int p = 0;
   Print (p);
//| Expert deinitialization function                                 |
void OnDeinit(const int reason)
//| Expert tick function                                             |
void OnTick()

The TestDLL contains just one function as listed in the code above. Anyway, am I missing something? Is there a solution to fix this issue?


fig01.png  10 kb
fig02.png  119 kb
fig03.png  10 kb

I think build 2280 64-bit has new bug.

Since build 2280 I have problems with those functions:

#import "user32.dll"
  int SetWindowLongA(int hWnd,int nIndex, int dwNewLong);
  int GetWindowLongA(int hWnd,int nIndex);
  int SetWindowPos(int hWnd, int hWndInsertAfter,int X, int Y, int cx, int cy, int uFlags);
  int GetParent(int hWnd);
  int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
  int RegisterWindowMessageA(string MessageName);


I build my DLL by MinGW-w64 like follows:

gcc -O3 -mavx2 -shared -o TickTrader2.dll dllmain.cpp TickTrader2.cpp

and I solved this problem.

You will get MinGW-w64 at

Download MinGW-w64 - for 32 and 64 bit Windows from
A complete runtime environment for gcc