This code perfectly works on PB v3, but it doesn't on v4 (i debugged it and it crashs on "ret", the "return adress" is overwritten, the local stack allocated is too small for all data)

Code: Select all
Procedure OpenNetworkConnectionEx(ServerName$, Port.l, TimeOut.l)
!Conn equ Esp+12
!Wsa equ Esp+28
!Tout equ Esp+428
!WaitX equ Esp+436
!Sock equ Esp+444
WsaData.WSADATA
Connection.SOCKADDR_IN
TimeOuts.TIMEVAL
WaitSock.ULARGE_INTEGER
Sock.l
!If ~ defined _gethostbyname@4 | defined @f
!extrn _gethostbyname@4
!@@:
!End If
!If ~ defined _WSAStartup@8 | defined @f
!extrn _WSAStartup@8
!@@:
!End If
!If ~ defined _socket@12 | defined @f
!extrn _socket@12
!@@:
!End If
!If ~ defined _htons@4 | defined @f
!extrn _htons@4
!@@:
!End If
!If ~ defined _ioctlsocket@12 | defined @f
!extrn _ioctlsocket@12
!@@:
!End If
!If ~ defined _connect@12 | defined @f
!extrn _connect@12
!@@:
!End If
!If ~ defined _select@20 | defined @f
!extrn _select@20
!@@:
!End If
!If ~ defined _closesocket@4 | defined @f
!extrn _closesocket@4
!@@:
!End If
!If ~ defined _WSACleanup@0 | defined @f
!extrn _WSACleanup@0
!@@:
!End If
!MOV Eax, [Esp]
!OR Eax, Eax
!JZ @f
!PUSH Eax
!CALL _gethostbyname@4
!OR Eax, Eax
!JZ @f
!MOVSX Ebx, word [Eax+8]
!CMP Ebx, 2
!JNE @f
!MOV Ecx, [Eax+12]
!MOV Ecx, [Ecx]
!MOV Ecx, [Ecx]
!MOV [Conn+4], Ecx
!LEA Eax, [Wsa]
!PUSH Eax
!PUSH $0002
!CALL _WSAStartup@8
!OR Eax, Eax
!JNZ @f
!CMP byte [Wsa], 2
!JL @f
!PUSH 6
!PUSH 1
!PUSH 2
!CALL _socket@12
!CMP Eax, -1
!JE @f
!MOV [Sock], Eax
!MOV word [Conn], 2
!PUSH dword [Esp+4]
!CALL _htons@4
!MOV word [Conn+2], ax
!MOV Eax, dword [Esp+8]
!MOV dword [Tout], Eax
!MOV dword [WaitX], 1
!MOV Eax, dword [Sock]
!MOV dword [WaitX+4], Eax
!LEA Eax, [WaitX]
!PUSH Eax
!PUSH -2147195266
!PUSH dword [Sock+8]
!CALL _ioctlsocket@12
!PUSH dword 16
!LEA Eax, [Conn+4]
!PUSH Eax
!PUSH dword [Sock+8]
!CALL _connect@12
!LEA Eax, [Tout]
!PUSH Eax
!PUSH 0
!LEA Eax, [WaitX+8]
!PUSH Eax
!PUSH 0
!PUSH 0
!CALL _select@20
!CMP Eax, 0
!JNA @f
!LEA Eax, [Tout+4]
!PUSH Eax
!PUSH -2147195266
!PUSH dword [Sock+8]
!CALL _ioctlsocket@12
!CALL _WSACleanup@0
!MOV Eax, [Sock]
ProcedureReturn
!@@:
!CMP dword [Sock], -1
!JNE @f
!PUSH dword [Sock]
!CALL _closesocket@4
!@@:
!CMP byte [Wsa], 0
!JE @f
!CALL _WSACleanup@0
!@@:
!Restore Conn
!Restore Wsa
!Restore Tout
!Restore WaitX
!Restore Sock
EndProcedure
InitNetwork()
Host$ = "www.purearea.net"
ServerID = OpenNetworkConnectionEx(Host$, 80, 1)
If ServerID = 0
MessageRequester("", "Timeout")
Else
MessageRequester("", "OK")
CloseNetworkConnection(ServerID)
EndIf
