Download MetaTrader 5
To add comments, please log in or register
Publish your articles and improve your rating!
NewWin
245
NewWin 2014.03.22 10:04 

Hi everyone,

I searched in forum but cannot find how to open an URL in MT4 and download a file from an URL. What I simply need is 2 scripts:

- One script that open an URL (string type) that given in input of the script.

- One script that download a file from an URL, such as: http://www.domain.com/folder/file.ext (whatever the file type is).

Can anyone help me? Thanks a lot.

qjol
3243
qjol 2014.03.22 19:40  
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#import "shell32.dll"
   int ShellExecuteW(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCommand);
#import
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
  ShellExecuteW(0, "Open","http://bit.ly/1gcKBFL", 0 , "", 0);
  }
//---
NewWin
245
NewWin 2014.03.23 01:59  

Thank you so much, gjol.

This is quite helpful.

By the way, how to use all function of DLL?

There are some DLL such as "shell32.dll", "wininet.dll", .etc... But how can I know all of their function as well as parameter's meaning?

Is there any document to instruct/guide about this (like mql4)?

Thanks again.

Jack Thomas
502
Jack Thomas 2014.03.23 03:37  
Kienvu:

Hi everyone,

I searched in forum but cannot find how to open an URL in MT4. What I simply need is a script that open an URL (string type) that given in input of the script.

Can anyone help me? Thanks a lot.

This might be helpful for you.

HTTP requests for new MQL4 (tested in build 600)


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

- CodeMonkey

qjol
3243
qjol 2014.03.23 08:54  
Kienvu:

There are some DLL such as "shell32.dll", "wininet.dll", .etc... But how can I know all of their function as well as parameter's meaning?

google is your friend

Is there any document to instruct/guide about this (like mql4)?

of course MSDN (no it's not like mql4)

NewWin
245
NewWin 2014.03.24 02:56  

I have tried this code from a post in forum, but when I run it nothing happened (I tried to download an image from an website). Can anyone know why?

#property copyright "Integer"
#property link "for-good-letters@yandex.ru"

#import "wininet.dll"
#property show_inputs

#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100

#import "wininet.dll"

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& iBuffer[], int lNumBytesToRead, int& lNumberOfBytesRead[]);
int InternetCloseHandle(int hInet);

extern string url = "http://www...../......./abc.jpg";
extern string FileName = "abc.jpg";

int start()
{
int hInternetSession = InternetOpenA("Microsoft Internet Explorer",0,"","",0);
if(hInternetSession <= 0)
{
Print("Opening Internet FAILED...");
return(-1);
}
string temp;
int iBuffer[256];
int dwBytesRead[1];
int hURL = InternetOpenUrlA(hInternetSession, url,"",0,INTERNET_FLAG_PRAGMA_NOCACHE,0);
if(hURL >0)
{
int fh = FileOpen(FileName,FILE_BIN|FILE_WRITE);
if(fh>=0) {
while(True) {
if(!InternetReadFile(hURL, iBuffer, ArraySize(iBuffer)*4, dwBytesRead)) {
Alert("InternetReadFile Error!");
break;
}
if(dwBytesRead[0]==0) break;
for(int i=0; i<dwBytesRead[0]; i++) {
int byte = (iBuffer[i/4] >> ((i & 3)*8)) & 0xff;
FileWriteInteger(fh,byte,CHAR_VALUE);
}
}
FileClose(fh);
}
else Alert("Error opening file ",FileName);
InternetCloseHandle(hURL);
}
InternetCloseHandle(hInternetSession);
return(0);
} 
qjol
3243
qjol 2014.03.24 03:34  

i assume you using B600 >...

you have to adapt your code for UNICODE so you have to use for instance InternetOpenW instead of InternetOpenA see an example here



NewWin
245
NewWin 2014.03.24 04:01  
Great thanks, gjol. It worked!
/
To add comments, please log in or register