MT4 release 1160 (and later) broke ability to call InternetOpenW()

 

Attached is a small script that calls InternetOpenW() (you need to enable DLL calls in your MT4 settings).

This script runs successfully without errors in MT4 releases prior to 1160.

In the builds 1160 and 1170 the call to InternetOpenW() returns error code 6 (invalid handle).

Is there a workaround?

MT4 release 1160 (and 1170) broke ability to call InternetOpenW()
MT4 release 1160 (and 1170) broke ability to call InternetOpenW()
  • 2018.12.27
  • www.mql5.com
Attached is a small script that calls InternetOpenW() (you need to enable DLL calls in your MT4 settings...
Files:
TestInet.mq4  1 kb
 
saleyn:

Attached is a small script that calls InternetOpenW() (you need to enable DLL calls in your MT4 settings).

This script runs successfully without errors in MT4 releases prior to 1160.

In the builds 1160 and 1170 the call to InternetOpenW() returns error code 6 (invalid handle).

Is there a workaround?

Read the documentation for this function on MSDN, you should not use empty string for lpszProxy and lpszProxyBypass, use NULL.

InternetOpenW function
InternetOpenW function
  • 2018.12.05
  • windows-sdk-content
  • docs.microsoft.com
Initializes an application's use of the WinINet functions.
 
Mohammad Hossein Sadeghi:

Read the documentation for this function on MSDN, you should not use empty string for lpszProxy and lpszProxyBypass, use NULL.

I tried both initializing string as NULL and as an empty string, but both calls in MT4 build 1160 and later result in InternetOpenW() returning NULL and system error 6.

Note that this NOT observed with given script in earlier MT4 builds.

 
saleyn:

I tried both initializing string as NULL and as an empty string, but both calls in MT4 build 1160 and later result in InternetOpenW() returning NULL and system error 6.

Note that this NOT observed with given script in earlier MT4 builds.

I used your script and it works on Windows 10, and MT4 build 1170.

2018.12.28 07:12:08.398 Script TestInet AUDCAD,H1: removed
2018.12.28 07:12:08.397 TestInet AUDCAD,H1: uninit reason 0
2018.12.28 07:12:08.327 TestInet AUDCAD,H1: Success
2018.12.28 07:12:08.327 TestInet AUDCAD,H1: initialized
2018.12.28 07:12:08.327 Script Test\TestInet AUDCAD,H1: loaded successfully

You may need to reset the setting of Internet Explorer at Control Panel.
 
Mohammad Hossein Sadeghi:

I used your script and it works on Windows 10, and MT4 build 1170.

2018.12.28 07:12:08.398 Script TestInet AUDCAD,H1: removed
2018.12.28 07:12:08.397 TestInet AUDCAD,H1: uninit reason 0
2018.12.28 07:12:08.327 TestInet AUDCAD,H1: Success
2018.12.28 07:12:08.327 TestInet AUDCAD,H1: initialized
2018.12.28 07:12:08.327 Script Test\TestInet AUDCAD,H1: loaded successfully

You may need to reset the setting of Internet Explorer at Control Panel.

Were you running it on a 32bit or 64bit OS?

Running this script on Windows Server 2012 32bit is successful, however, I am getting the same error on all 64bit Windows 10 machines (tested 4 of them).

Which settings do you suggest to reset in Control Panel?

 
saleyn:

Were you running it on a 32bit or 64bit OS?

Running this script on Windows Server 2012 32bit is successful, however, I am getting the same error on all 64bit Windows 10 machines (tested 4 of them).

Which settings do you suggest to reset in Control Panel?

It's 64bit. Just default setting: Control Panel>Internet Options>Advanced(tab)>Reset.

 
Mohammad Hossein Sadeghi:

It's 64bit. Just default setting: Control Panel>Internet Options>Advanced(tab)>Reset.

Resetting Internet Options doesn't seem to help, still getting same error:

2018.12.28 11:33:50.814 TestInet BTCUSD,Daily: uninit reason 0
2018.12.28 11:33:50.814 TestInet BTCUSD,Daily: Error in InternetOpenW: 6
2018.12.28 11:33:50.814 TestInet BTCUSD,Daily: initialized
2018.12.28 11:33:50.807 Script Test\TestInet BTCUSD,Daily: loaded successfully

Same result on 4 different machines.

The question is really why does it work with MT4 builds prior to 1160, and doesn't work with the 1160 onward?

Below is the result of running the same script on the same machine, MT4 build 1090:

2018.12.28 12:12:13.328 TestInet AUDCHF,Daily: uninit reason 0
2018.12.28 12:12:13.328 TestInet AUDCHF,Daily: Success
2018.12.28 12:12:13.328 TestInet AUDCHF,Daily: initialized
2018.12.28 12:12:13.322 Script Test\TestInet AUDCHF,Daily: loaded successfully
Clearly this seems to have something to do with the MT4 upgrade.
 
saleyn:

Resetting Internet Options doesn't seem to help, still getting same error:

Same result on 4 different machines.

The question is really why does it work with MT4 builds prior to 1160, and doesn't work with the 1160 onward?

Below is the result of running the same script on the same machine, MT4 build 1090:

Clearly this seems to have something to do with the MT4 upgrade.

Try this code:

//+------------------------------------------------------------------+
//|                                                     TestInet.mq4 |
//+------------------------------------------------------------------+
#property strict

#import "Wininet.dll"
int InternetAttemptConnect(int x);
//int InternetOpenW(string &sAgent,int lAccessType,string &sProxyName,string &sProxyBypass,int lFlags);
int InternetOpenW(string sAgent,int lAccessType,string sProxyName,string sProxyBypass,int lFlags);
int InternetCloseHandle(int hInet);
#import

#import "ntdll.dll"
  int RtlGetLastWin32Error();
#import

void OnStart()
{
  int rv = InternetAttemptConnect(0);
  if (rv != 0)
    PrintFormat("Error in InternetAttemptConnect: %d", RtlGetLastWin32Error());

  string user_agent="Mozilla";
  //string nill="";
  //int session=InternetOpenW(user_agent,0,nill,nill,0);
  int session=InternetOpenW(user_agent,0,NULL,NULL,0);
  if (session==0)
    PrintFormat("Error in InternetOpenW: %d", RtlGetLastWin32Error());
  else {
    Print("Success");
    InternetCloseHandle(session);
  }
}

Strings are passed by value when importing and NULL is passed to InternetOpenW instead of nill.

 
Mohammad Hossein Sadeghi:

Try this code:

Strings are passed by value when importing and NULL is passed to InternetOpenW instead of nill.

Same result with the error:

2018.12.28 13:00:28.248 TestInet NZDCHF,M5: uninit reason 0
2018.12.28 13:00:28.248 TestInet NZDCHF,M5: Error in InternetOpenW: 6
2018.12.28 13:00:28.247 TestInet NZDCHF,M5: initialized
2018.12.28 13:00:28.237 Script Test\TestInet NZDCHF,M5: loaded successfully
 
saleyn:

Same result with the error:

Works for me. Windows 10/64 MT4 1170.

2018.12.28 16:05:23.400    296477 EURUSD,H1: initialized
2018.12.28 16:05:23.478    296477 EURUSD,H1: Success
2018.12.28 16:05:23.500    296477 EURUSD,H1: uninit reason 0

 

I have hard time understanding the cause of this problem.

I tried running this script on 4 Windows 10 machines (with latest upgrades) on PCs in 2 different networks, and consistently get errors in 1170 MT4 build, while getting successful results on MT4 built 1090 running on the same machines.  The only variable is the versions of MT4 software.

According to several users in this thread they can't reproduce this problem on build 1170.

This is rather annoying, and makes some of the EAs and indicators I've written that have been working for years unusable with the latest MT4 builds.

Reason: