Weird MQL4 Bug ??

 

Hello i just create a custom indicator and it works well..

i decide to add some function using windows dll.. i use all different variable's name, so i'm 100% sure that no overlapped variable name.


But its strange that after i add the function, the procedure affect the indicator calculation... so the visual also change...



The function i add is on online fetch data :

#import "wininet.dll"
int InternetOpenA(string a0, int a1, string a2, string a3, int a4);
int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5);
int InternetReadFile(int a0, string a1, int a2, int& a3[]);
int InternetCloseHandle(int a0);
int Buffer_LEN = 13;
int hSession_IEType;
int hSession_Direct;
int Internet_Open_Type_Preconfig = 0;
int Internet_Open_Type_Direct = 1;
int Internet_Open_Type_Proxy = 3;

int Session(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 (Direct)
{
return(hSession_Direct);
}
else
{
return(hSession_IEType);
}
}
bool GrabWeb(string strUrl, string &strWebPage) {
int lReturn[] = {1};
string sBuffer = "x";
int hInternet = InternetOpenUrlA(Session(0), strUrl, "0", 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);

if (hInternet == 0) return (FALSE);
int iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn);
if (iResult == 0) return (FALSE);
int bytes = lReturn[0];
for (strWebPage = StringSubstr(sBuffer, 0, lReturn[0]); lReturn[0] != 0; strWebPage = strWebPage + StringSubstr(sBuffer, 0, lReturn[0])) {
iResult = InternetReadFile(hInternet, sBuffer, Buffer_LEN, lReturn);
if (lReturn[0] == 0) break;
bytes += lReturn[0];
}
iResult = InternetCloseHandle(hInternet);
if (iResult == 0) return (FALSE);
return (TRUE);
}


i would like to know how to solve this problem ? is this a bug from mql4 ? i checked.. 100% no overlap variable, logically this function should not affect indicator calculation...

 

It's really funny.. that i "suddenly" solve this problem by adding a lot of space for strWebPage variable


so after function declaration (grabweb).. i add

strWebPage=" ";


and it looks like solve the problem,


all calculation done by grab web does not had relation with the main calculation ... but it did affect my main calculation...????!!

How can this happen, in my 6 years of coding, never found this kind of weird behavior... hope seasoned mql4 programmer can light my mind...


help me

 
i faced this function many many times from clients and for some strange reason that way you suggested solves this problem. i think it has todo with windows and mql converting issues, did not check it more detailed. everyone is using same function for some reason.
 
??
 

From my point of view, I can see problem:

Buffer_LEN = 13 while the real length of the passed sBuffer is 1. The windows function overwrites 13 bytes while you allocated only 1. The result may do anything, it mostly crashes MT4.

Correct allocation for 13 bytes is string sBuffer = "xxxxxxxxxxxxx";

 
Ovo:

From my point of view, I can see problem:

Buffer_LEN = 13 while the real length of the passed sBuffer is 1. The windows function overwrites 13 bytes while you allocated only 1. The result may do anything, it mostly crashes MT4.

Correct allocation for 13 bytes is string sBuffer = "xxxxxxxxxxxxx";


thank you.

your explanation sounds reasonable.

Reason: