MetaTrader 4 Build 574 with Updated MQL4 Language and Market of Applications Released - page 16

 

I have very big problem with new update of meta trader and new meta editor with in fact mql5 inside meta trader 4...

I fixed all warnings about typecasting and new uint dataype...

but all windows api that I use does not work enymore.

with old version, with this same code I never had problems...

they are 3

1- internet wininet

 #import "wininet.dll"



#define INTERNET_FLAG_PRAGMA_NOCACHE    0x00000100 // Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy.

#define INTERNET_FLAG_NO_CACHE_WRITE    0x04000000 // Does not add the returned entity to the cache. 

#define INTERNET_FLAG_RELOAD            0x80000000 // Forces a download of the requested file, object, or directory listing from the origin server, not from the cache.



int InternetOpenA(

        string  sAgent,

        uint            lAccessType,

        string  sProxyName="",

        string  sProxyBypass="",

        int     lFlags=0

);



int InternetOpenUrlA(

        int     hInternetSession,

        string  sUrl, 

        string  sHeaders="",

        int     lHeadersLength=0,

        uint    lFlags=0,

        int     lContext=0 

);



int InternetReadFile(

        int     hFile,

        string  sBuffer,

        int     lNumBytesToRead,

        int&    lNumberOfBytesRead[]

);



int InternetCloseHandle(

        int     hInet

);

#import





int hSession(bool Direct)

{

        string InternetAgent;

        if (hSession_IEType == 0)

        {

                InternetAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)";

                hSession_IEType = InternetOpenA(InternetAgent, Internet_Open_Type_Preconfig, "0", "0", 0);

                hSession_Direct = InternetOpenA(InternetAgent, Internet_Open_Type_Direct, "0", "0", 0);

        }

        if (bWinInetDebug) 

                Log("hsession_ietype: " + DoubleToStr(hSession_IEType,0));

        if (bWinInetDebug) 

                Log("hsession_direct: " + DoubleToStr(hSession_Direct,0));

                

        if (Direct) 

        { 

                return(hSession_Direct); 

        }

        else 

        {

                return(hSession_IEType); 

        }

}

        int     hInternet;

        int             iResult;

        int     lReturn[]       = {1};

        string  sBuffer         = "                                                                                                                                                                                                                                                               ";    // 255 spaces

        int     bytes;

        bWinInetDebug = EnableLogging;  //added by euclid

        hInternet = InternetOpenUrlA(hSession(FALSE), strUrl, "0", 0, 

                                                                INTERNET_FLAG_NO_CACHE_WRITE | 

                                                                INTERNET_FLAG_PRAGMA_NOCACHE | 

                                                                INTERNET_FLAG_RELOAD, 0);

                                                                

        if (bWinInetDebug) 

                Log("hInternet: " + hInternet);   

        if (hInternet == 0) 

                return(false);

hInternet is always 0... so the wininet function fails (before, with old meta trader version it works very good)


2- GetVolumeInformationA

#import "Kernel32.dll"

  bool GetVolumeInformationA(string RootPathName,

       string VolumeNameBuffer, int VolumeNameSize,

       int& VolumeSerialNumber[], int MaximumComponentLength,

       int FileSystemFlags, string FileSystemNameBuffer,

       int FileSystemNameSize);



#import "stdlib.ex4"

string IntegerToHexString(int integer_number);

string SystemDriveSerialNumber(string sDrive) {

  int    iVolumeSerialNumber[1]={0};

  string sVolumeSerialNumber="";

  if(GetVolumeInformationA(sDrive+":\\", "                ", 15, iVolumeSerialNumber, 0, 0, "                ", 15))

  {

    sVolumeSerialNumber=IntegerToHexString(iVolumeSerialNumber[0]);

    sVolumeSerialNumber=StringConcatenate(StringSubstr(sVolumeSerialNumber,0,4), "-", StringSubstr(sVolumeSerialNumber,4));

  }

  return(sVolumeSerialNumber);

}

It always failt and return "" (before worked very good... never fail)

3- messagebox

 #import "user32.dll"

   int    MessageBoxA(int hWnd, string lpText, string lpCaption, int uType);

   

#import

//  MessageBoxA Parameters:

//  hWnd      -   Windowshandle() Chart symbol

//  lpText    -   Optional text that contains the message to be displayed. or NULL 

//  lpCaption -   Optional text to be displayed in the header of the dialog box. If NULL displays the expert name. 

//  uType     -   Optional flags that determine the type of buttons displayed as per flags in MessageBox().

//                eg. MB_OK MB_OKCANCEL MB_YESNO

//  return codes - As MessageBox() eg IDOK IDCANCEL IDABORT IDYES IDCONTINUE says these buttons were selected                  

//  PostMessageA Parameters:

//               PostMessageA(hWnd, WM_COMMAND, mydefine, 0);

//  hWnd      -   Windowshandle() Chart symbol

//  WM_COMMAND-   Windows Command instruction

//  mydefine  -   Any #define integer from aswincmds.mqh  

//---- input parameters . WinUser32 above is required for messagebox



// messageboxA and PostMessageA variables

       hWnd=WindowHandle(Symbol(),0);                                               

      lpText="ERROR";

      lpCaption="INVALID LICENSE "+WindowExpertName();

      uType=MB_OK;

      MessageBoxA(hWnd,lpText,lpCaption,uType);

seems like windows api function have to be called in different way from new mql platform update

anyone know how can those problems be fixed?

 
mikol:
int InternetOpenUrlA(
bool GetVolumeInformationA(string R
int    MessageBoxA(int hWnd, string lpText, string lpCaption, int uType);

seems like windows api function have to be called in different way from new mql platform update

anyone know how can those problems be fixed?

From the first page of this thread:
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.
So do you really expect to be able to use the Ansi versions?
 
WHRoeder:
From the first page of this thread: So do you really expect to be able to use the Ansi versions?

No I don't expect to be able to use the Ansi version, not anymore. :-)

I didn't read this information. Thank you for the fast reply.

I tried to call the InternetOpen instead of InternetOpenA in wininet.dll but I get the error "unresolved import function call"

where is my approach mistaken?

maybe I have to call the "W" version?

Thanks!

 
mikol:

No I don't expect to be able to use the Ansi version, not anymore. :-)

I didn't read this information. Thank you for the fast reply.

I tried to call the InternetOpen instead of InternetOpenA in wininet.dll but I get the error "unresolved import function call"

where is my approach mistaken?

maybe I have to call the "W" version?

Thanks!


Ok now works everything exept InternetOpenUrlW

it always return 0

I checked hSession and it seems valid

 
mikol:


Ok now works everything exept InternetOpenUrlW


The following works for me:

#import "wininet.dll"
   int InternetOpenW(string, int, string, string, int);
   int InternetOpenUrlW(int, string, string, int, int, int);
#import


int hInternet = InternetOpenW("anything", 0 /* = INTERNET_OPEN_TYPE_PRECONFIG */, NULL, NULL, 0);
if (hInternet == 0) {
   Print("InternetOpenW() failed");
} else {
   int hInternetUrl = InternetOpenUrlW(hInternet, "http://www.google.com", NULL, 0, 0, 0);
   if (hInternetUrl == 0) {
      Print("InternetOpenUrlW() failed");
   } else {
      Print("Okay: url handle: ", hInternetUrl);
   }
}

However, your next problem will be that InternetReadFile() collects the raw response from the web server. This will be Ansi text which needs to be converted to Unicode.

 
gchrmt4:


The following works for me:

However, your next problem will be that InternetReadFile() collects the raw response from the web server. This will be Ansi text which needs to be converted to Unicode.


I fixed InternetOpenUrlW

InternetOpenUrlA did accept "0" (don't know why) as third parameter, while the "W" version works only with "" (or NULL suppose seeing your example)

about the translation from Ansi to Unicode today I'm lucky. I just call a php on my webserver with some parameters and the response can be only "0" or "1" something different for my purpose is an invalid response. It's working fine.

but just in case... how can be done the conversion task from ansi to unicode?

 
mikol:

but just in case... how can be done the conversion task from ansi to unicode?

It's possible to use MultiByteToWideChar(), but there are issues around passing strings by reference into DLL. It's easier to make use of the fact that FileOpen() does Unicode-to-Ansi translation: write the server response into a temporary file, and then read it back from there.
 
mikol:


I fixed InternetOpenUrlW

InternetOpenUrlA did accept "0" (don't know why) as third parameter, while the "W" version works only with "" (or NULL suppose seeing your example)

about the translation from Ansi to Unicode today I'm lucky. I just call a php on my webserver with some parameters and the response can be only "0" or "1" something different for my purpose is an invalid response. It's working fine.

but just in case... how can be done the conversion task from ansi to unicode?


have a look here: https://www.mql5.com/ru/forum/113746
 
gchrmt4:
It's possible to use MultiByteToWideChar(), but there are issues around passing strings by reference into DLL. It's easier to make use of the fact that FileOpen() does Unicode-to-Ansi translation: write the server response into a temporary file, and then read it back from there.

Ok thanks. How do yu manage backwardscompatibility...? new compiled experts are deleted if loaded in old meta trader and old meta trader compiled files does not work properly in the new version of the platform...
 

I feel something smelly with the 577 update.

Custom indicators behave very strange, I did not find clue yet, but I feel big trouble in the air... Problems are both with the original 509 ex4 and those compiled in 574/577 running on the start() method.