Libraries: mt4R for new MQL4

 

mt4R for new MQL4:

mt4R, modified for supporting new MQL4

Author: micclly

 

Thanks for your contribution.

It's nice to know somebody takes care about useful projects.

best regards

 

Thanks for your contribution.

It's nice to know somebody takes care about useful projects.

best regards

 
acushnir:

Thanks for your contribution.

It's nice to know somebody takes care about useful projects.

best regards


Can you specify what changes were necessary to update the dll? I wasn't aware that dlls need to be changed to fit MQL5's format. Have you any links on this subject?
 
acushnir:

Thanks for your contribution.

It's nice to know somebody takes care about useful projects.

best regards


Can you specify what changes were necessary to update the dll? I wasn't aware that dlls need to be changed to fit MQL5's format. Have you any links on this subject?
 
FXEZ:
Can you specify what changes were necessary to update the dll? I wasn't aware that dlls need to be changed to fit MQL5's format. Have you any links on this subject?

string in new MQL4 is not an array of char but an array of wchar_t.

If your old indicator/script/EA which worked on MT4 build509 or earlier uses string and passes it to DLL functions, you MUST change the function to wchar_t version.

For example, if it uses ShellExecuteA, change it to ShellExecuteW.

Unfortunately if the dll you use does not provide wchar_t version functions like mt4R.dll, you must modify DLL implementation, or convert an string to an array of char by WideCharToMultiByte Win32API.

Note: I haven't tried WideCharToMultiByte yet on new MQL4, so I don't know you can use WideCharToMultiByte without or with any problem.

At the build 600 release topic, it is said as follows:

Changes in MQL4 Language

  • Strings are now presented in Unicode format, though they were in ANSI format (single byte ones) before. That should be considered if the program uses DLLs and passes string variables to them. When calling Windows API functions, Unicode versions of these functions should be used.
 
FXEZ:
Can you specify what changes were necessary to update the dll? I wasn't aware that dlls need to be changed to fit MQL5's format. Have you any links on this subject?

string in new MQL4 is not an array of char but an array of wchar_t.

If your old indicator/script/EA which worked on MT4 build509 or earlier uses string and passes it to DLL functions, you MUST change the function to wchar_t version.

For example, if it uses ShellExecuteA, change it to ShellExecuteW.

Unfortunately if the dll you use does not provide wchar_t version functions like mt4R.dll, you must modify DLL implementation, or convert an string to an array of char by WideCharToMultiByte Win32API.

Note: I haven't tried WideCharToMultiByte yet on new MQL4, so I don't know you can use WideCharToMultiByte without or with any problem.

At the build 600 release topic, it is said as follows:

Changes in MQL4 Language

  • Strings are now presented in Unicode format, though they were in ANSI format (single byte ones) before. That should be considered if the program uses DLLs and passes string variables to them. When calling Windows API functions, Unicode versions of these functions should be used.
 
Thanks for the explanation, and the update!
 
Thanks for the explanation, and the update!
 

Fist of all: Thank you so much for porting it to the new version! Excellent job!

However, I've encountered a problem. See this simple script:

//+------------------------------------------------------------------+
//|                                                  TestNewMt4R.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#include <mt4R.mqh>
#define RPATH "D:/Program Files/R/R-3.0.2/bin/i386/Rterm.exe --no-save"
#define RDEBUG 2
string times[1000];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   StartR(RPATH,RDEBUG);
   for(int i=0; i<1000; i++)
     {
      times[i]=TimeToString(iTime(Symbol(),Period(),i),TIME_DATE|TIME_SECONDS);
     }
   Rf("times",times);
   Rx("gc()");
   StopR();  
  }
//+------------------------------------------------------------------+

It crashes when trying to execute

Rf("times",times);

And I don't know why. I think the problem might be the one you mentioned regarding strings. However, I cannot resolve it by myself so help is very much appreciated.

Thanks!

EDIT:

I checked DebugView and it seems that the whole String handling is somehow broken, e.g.,

void OnStart()
  {
   StartR(RPATH,RDEBUG);
   string testString = "This is a string copy test.";
   
   Rs("rString", testString);
   
   Rx("gc()");
   StopR();
  }

Results in:

Wrong copy of string

 

Fist of all: Thank you so much for porting it to the new version! Excellent job!

However, I've encountered a problem. See this simple script:

//+------------------------------------------------------------------+
//|                                                  TestNewMt4R.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict
#include <mt4R.mqh>
#define RPATH "D:/Program Files/R/R-3.0.2/bin/i386/Rterm.exe --no-save"
#define RDEBUG 2
string times[1000];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   StartR(RPATH,RDEBUG);
   for(int i=0; i<1000; i++)
     {
      times[i]=TimeToString(iTime(Symbol(),Period(),i),TIME_DATE|TIME_SECONDS);
     }
   Rf("times",times);
   Rx("gc()");
   StopR();  
  }
//+------------------------------------------------------------------+

It crashes when trying to execute

Rf("times",times);

And I don't know why. I think the problem might be the one you mentioned regarding strings. However, I cannot resolve it by myself so help is very much appreciated.

Thanks!

EDIT:

I checked DebugView and it seems that the whole String handling is somehow broken, e.g.,

void OnStart()
  {
   StartR(RPATH,RDEBUG);
   string testString = "This is a string copy test.";
   
   Rs("rString", testString);
   
   Rx("gc()");
   StopR();
  }

Results in:

Wrong copy of string