I trying to change this code ( http://codebase.mql4.com/ru/1064 ) to download binary data, a .gif file from the nasdaq web site
Here is what I did, but the data download is corrupted
Thank You
Here is what I did, but the data download is corrupted
Thank You
Inserted Code
//+------------------------------------------------------------------+ //| s_wininet.mq4 | //| * | //| * | //+------------------------------------------------------------------+ #property copyright "Integer" #property link "[email protected]" //---- #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); } //+------------------------------------------------------------------+