using winhttp in metatrader4

 

hi, I have used this great article for mt5 to connect to a wss api. which is working fine. 

but the same code in mt4 does not work at the very first line  

 long http_open_result = WinHttpOpen("mt4",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,NULL,NULL,/*reserved parameter*/0);

I think sending that string is facing problem.

"stack damaged, check DLL function call"


I searched a lot but yet I couldn't find a solution on how to send string from mt4 to winhttp.dll  and it accepts it.

I think there maybe issue between 64bit ( mt5)  and 32 bit ( mt4 )  as in 64 bit  strings are 8 byte and in 32 bit they are 4bytes.

but they say the recent versions of mt4  is also 64 bit . so how a dll is working from mt5 but crashing from mt4 ?

maybe I should use a solution like creating a custom dll . sending data to this middle dll , and that handles the connections to the windows dll ?


https://www.mql5.com/en/forum/143101#comment_3618861

https://www.mql5.com/en/forum/150219

https://www.mql5.com/en/forum/150000


any helps/ideas would be appreciated.


#include<winhttp.mqh>
#import "winhttp.dll"
long WinHttpOpen(string,ulong,string,string,ulong);
HINTERNET WinHttpConnect(HINTERNET,string,INTERNET_PORT,ulong);
HINTERNET WinHttpOpenRequest(HINTERNET,string,string,string,string,string,ulong);
bool WinHttpSetOption(HINTERNET,ulong,LPVOID[],ulong);
bool WinHttpQueryOption(HINTERNET,ulong,LPVOID[],ulong&);
bool WinHttpSetTimeouts(HINTERNET,int,int,int,int);
HINTERNET WinHttpSendRequest(HINTERNET,string,ulong,LPVOID[],ulong,ulong,ulong);
bool WinHttpReceiveResponse(HINTERNET,LPVOID[]);
HINTERNET WinHttpWebSocketCompleteUpgrade(HINTERNET,ulong&);
bool WinHttpCloseHandle(HINTERNET);
ulong WinHttpWebSocketSend(HINTERNET,WINHTTP_WEB_SOCKET_BUFFER_TYPE,BYTE&[],ulong);
ulong WinHttpWebSocketReceive(HINTERNET,BYTE&[],ulong,ulong&,WINHTTP_WEB_SOCKET_BUFFER_TYPE&);
ulong WinHttpWebSocketClose(HINTERNET,ushort,BYTE&[],ulong);
ulong WinHttpWebSocketQueryCloseStatus(HINTERNET,ushort&,BYTE&[],ulong,ulong&);
#import


long http_open_result = WinHttpOpen("mt4",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,NULL,NULL,/*reserved parameter*/0);


WebSockets for MetaTrader 5 — Using the Windows API
WebSockets for MetaTrader 5 — Using the Windows API
  • www.mql5.com
In this article, we will use the WinHttp.dll to create a WebSocket client for MetaTrader 5 programs. The client will ultimately be implemented as a class and also tested against the Binary.com WebSocket API.