Get binary data from with wininet.dll --- internetOpenUrlA ?

 

Can some one help me change this code ( https://www.mql5.com/ru/code/7089 ) to donwload binary data, a .gif file from the nasdaq web site

Here is what I did, but the data download is corrupted

Thank You

//+------------------------------------------------------------------+
//|                                                    s_wininet.mq4 |
//|                                                                * |
//|                                                                * |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link      "for-good-letters@yandex.ru"
//----
#import "wininet.dll"
int InternetAttemptConnect (int x);
  int InternetOpenA(string sAgent, int lAccessType, 
                    string sProxyName = "", string sProxyBypass = "", 
                    int lFlags = 0);
  int InternetOpenUrlA(int hInternetSession, string sUrl, 
                       string sHeaders = "", int lHeadersLength = 0,
                       int lFlags = 0, int lContext = 0);
  int InternetReadFile(int hFile, int& sBuffer[], int lNumBytesToRead, 
                       int& lNumberOfBytesRead[]);
  int InternetCloseHandle(int hInet);
#import
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   if(!IsDllsAllowed())
     {
       Alert("?????????? ? ?????????? ????????? ????????????? DLL");
       return(0);
     }
   int rv = InternetAttemptConnect(0);
   if(rv != 0)
     {
       Alert("?????? ??? ?????? InternetAttemptConnect()");
       return(0);
     }
   int hInternetSession = InternetOpenA("Microsoft Internet Explorer", 
                                        0, "", "", 0);
   if(hInternetSession <= 0)
     {
       Alert("?????? ??? ?????? InternetOpenA()");
       return(0);         
     }
   int hURL = InternetOpenUrlA(hInternetSession, 
              "http://content.nasdaq.com/graphs/HOMEIXIC.gif?111565", "", 0, 0, 0);
   if(hURL <= 0)
     {
       Alert("?????? ??? ?????? InternetOpenUrlA()");
       InternetCloseHandle(hInternetSession);
       return(0);         
     }      
   int cBuffer[256];
   int dwBytesRead[1]; 
   string TXT = "";
   while(!IsStopped())
     {
       bool bResult = InternetReadFile(hURL, cBuffer, 1024, dwBytesRead);
       if(dwBytesRead[0] == 0)
           break;
       string text = "";   
       for(int i = 0; i < 256; i++)
         {
              text = text + CharToStr(cBuffer[i] & 0x000000FF);
              if(StringLen(text) == dwBytesRead[0])
                  break;
              text = text + CharToStr(cBuffer[i] >> 8 & 0x000000FF);
              if(StringLen(text) == dwBytesRead[0])
                  break;
           text = text + CharToStr(cBuffer[i] >> 16 & 0x000000FF);
           if(StringLen(text) == dwBytesRead[0])
               break;
           text = text + CharToStr(cBuffer[i] >> 24 & 0x000000FF);
         }
       TXT = TXT + text;
       Sleep(1);
     }
   if(TXT != "")
     {
       int h = FileOpen("SavedFromInternet.htm", FILE_BIN|FILE_WRITE);
       if(h > 0)
         {
           FileWrite(h,TXT);
           FileClose(h);
           Alert("??????! ??. ???? .../experts/files/image.gif");
         }
       else
         {
           Alert("?????? ??? ?????? FileOpen()");
         }
     }
   else
     {
       Alert("??? ????????? ??????");
     }
   InternetCloseHandle(hInternetSession);
   Sleep ( 10000);
   return(0);
}
//+------------------------------------------------------------------+
 

Or have any one use winivet FTP ?

int InternetOpenA(string sAgent, int lAccessType, string sProxyName = "", string sProxyBypass = "", int lFlags = 0);
int InternetConnectA(int hInternetSession, string FTPURL, int port, string login, string password, int FTPflag, int lFlags = 0, int lFlags = 0);
int FtpGetFileA(int hSession, string FileNameServer, string FileNameLocal, bool Boolean, int lFlags =0, int lFlags =1, int lFlags = 0);
int FtpPutFileA(int hSession, string FileNameLocal, string FileNameServer, int lFlags =1, int lFlags =0);

int FtpDeleteFileA(int hSession, string FileNameServer);

 

hi, i've written a very basic library that handles binary data as well

https://www.mql5.com/en/code/10121

i hope you can find some inspiration =)