The new MQL4 syntax - page 5

 
gchrmt4:
Still not sure if I understand but... I don't think you can declare the MQL4 import as void*. You have to use a specific data type in the import, and you can then only use the DLL import with that data type. If you want to use the same DLL function with different data types, then you have a problem unless there is a workaround such as https://www.mql5.com/en/forum/148934


Actually I am using a workaround, but it is quite weak - wrapping any type into a generic struct. Accepting a generic structure as parameter may change in any future release.This does not work with arrays, however.

 
Ovo:


Actually I am using a workaround, but it is quite weak - wrapping any type into a generic struct. Accepting a generic structure as parameter may change in any future release.This does not work with arrays, however.

... It seems that I'm wrong. What we're both forgetting is that MQL4 now has function overloading, and therefore it's possible to do something like this:

#import "AnyDll.dll"
   void Test(TestStruct &[]);
   void Test(int &[]);
#import 
 
gchrmt4:

... It seems that I'm wrong. What we're both forgetting is that MQL4 now has function overloading, and therefore it's possible to do something like this:


Sure, that is what I talk about since beginning :)

So far my import looks like:

bool ReadFile(int, MT4Structure&, uint, uint&[],int); // wrapper for all simple types / structures
bool ReadFile(int, double&[], uint, uint&[],int);
bool ReadFile(int, int&[], uint, uint&[],int);
bool ReadFile(int, uchar&[], uint, uint&[],int);
bool ReadFile(int, MT4Structure&[], uint, uint&[],int); // this does not work

and I wonder how long this list (for a single import) becomes in a year...

 

I also noticed small inconsistency in compilation of code with dependency on included files.

If two or more projects share the same include, and the include file gets modified, than the first projects detects it and recompiles, while the next projects do not. It is not serious problem though (we may delete all the ex4 any time).

 

I need just a quick answer, I am tired too search it today. Is it possible to destroy scope2 before it reaches the block boundary? I do not think so, but better to ask.

{
   MT4Scope* scope = new MT4Scope(_Symbol, 222);
   MT4Scope scope2(_Symbol, 223);
   delete scope; // calls destructor
   // here I want to call scope2 destructor, but I do not know how

   // some additional code
}
 
Ovo: I need just a quick answer, I am tired too search it today. Is it possible to destroy scope2 before it reaches the block boundary? I do not think so, but better to ask.
No.
 
ubzen:
No.


Thank you.
 

Why is "ArrayMaximum" different between MT4 600+ and MT5? I thought reason to migrate MT4 syntax to MT5 syntax was to make it easy to develop applications that worked on both?!?!


MT4

int  ArrayMaximum(
   const void&   array[],             // array for search
   int           count=WHOLE_ARRAY,   // number of checked elements
   int           start=0              // index to start checking with
   );


MT5

int  ArrayMaximum(
   const void&   array[],             // array for search
   int           start=0,             // index to start checking with
   int           count=WHOLE_ARRAY    // number of checked elements
   );
 
dlewisfl:

Why is "ArrayMaximum" different between MT4 600+ and MT5? I thought reason to migrate MT4 syntax to MT5 syntax was to make it easy to develop applications that worked on both?!?!

Probably to try and maintain some backwards compatibility . . .
 
dlewisfl: Why is "ArrayMaximum" different between MT4 600+ and MT5? I thought reason to migrate MT4 syntax to MT5 syntax was to make it easy to develop applications that worked on both?!?!
Not good. So make your own:
int iArrayMaximum(const void& array[], int iLimit=WHOLE_ARRAY, int iBeg=0){
   if(iLimit == WHOLE_ARRAY) iLimit = ArraySize(array);
#ifdef __MQL4__
   return( ArrayMaximum(array, iLimit - iBeg + 1, iBeg) );
#else
   return( ArrayMaximum(array, iBeg, iLimit - iBeg + 1) );
#endif
}
Problem solved.