MT5 compiler bug #3 with macros

 

Try to compile ...

#import "user32.dll"
   int      GetParent(int hWnd);
#import

#define __MT_HWNDCHART (user32::GetParent(__MT_HWND))
#define __CHARTID      (::ChartID())
#define __MT_HWND      (::ChartGetInteger(__CHARTID,CHART_WINDOW_HANDLE))
   
int OnInit()
  {
  //--- This will produce warning - possible loss of data due to type conversion
  int hwnd=__MT_HWNDCHART;
  
  //--- This will produce warning - possible loss of data due to type conversion
  int hwnd2=user32::GetParent(__MT_HWND);

  //--- This will compile
  int hwnd3=user32::GetParent(0);
  
  return(INIT_SUCCEEDED);
  }
 
Doerk Hilger:

Try to compile ...

#import "user32.dll"
   int      GetParent(long hWnd);
#import


Use long as the hWnd data type,
ChartGetInteger() returns long type not int.

 

You´re right, this seemed to be my mistake. Thank you, overlooked this.

But you cannot replace "int" by "long", the parameter must be casted. 


#import "user32.dll"
   int      GetParent(int hWnd);
#import

#define __MT_HWNDCHART (user32::GetParent((int)__MT_HWND))
#define __CHARTID      (::ChartID())
#define __MT_HWND      (::ChartGetInteger(__CHARTID,CHART_WINDOW_HANDLE))
   
int OnInit()
  {
  //--- This will compile
  int hwnd=__MT_HWNDCHART;
  
  //--- This will compile
  int hwnd2=user32::GetParent((int)__MT_HWND);

  //--- This will compile
  int hwnd3=user32::GetParent(0);
  
  return(INIT_SUCCEEDED);
  }
 
Doerk Hilger:

You´re right, this seemed to be my mistake. Thank you, overlooked this.

But you cannot replace "int" by "long", the parameter must be casted. 


are you referring to the GetParent() parameter?
if so why?

 
Doerk Hilger:

Try to compile ...

#ifdef __MQL4__
#define HWND   int
#else 
#define HWND   long
#endif 

#import "user32.dll"
   HWND      GetParent(HWND hWnd);
#import

#define __MT_HWNDCHART (user32::GetParent(__MT_HWND))
#define __CHARTID      (::ChartID())
#define __MT_HWND      (::ChartGetInteger(__CHARTID,CHART_WINDOW_HANDLE))
   
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  //--- This will produce warning - possible loss of data due to type conversion
  HWND hwnd=__MT_HWNDCHART;
  
  //--- This will produce warning - possible loss of data due to type conversion
  HWND hwnd2=user32::GetParent(__MT_HWND);

  //--- This will compile
  HWND hwnd3=user32::GetParent(0);
   
  }
 
Alain Verleyen:

Are you sure that HWND is 64bit when "winuser32.dll" is called from MT5? I use plenty of windows function and have all types the same within MT4 and MT5 and everything works without problems. A function like GetParent() has only one parameter, which is not a problem cause its just the stack size that changes, but what happens when you call function that takes 2 or more parameters?

 
Doerk Hilger:

Are you sure that HWND is 64bit when "winuser32.dll" is called from MT5? I use plenty of windows function and have all types the same within MT4 and MT5 and everything works without problems. A function like GetParent() has only one parameter, which is not a problem cause its just the stack size that changes, but what happens when you call function that takes 2 or more parameters?

Yes I am sure, try it. I can't answer for other functions.
 
Good hint, will have a look at it. But I am wondering why it all works with 32 bit params ... but I am not sure if I made usage of winuser32.dll, could also be wininet.dll 
Reason: