Code: Select all
#INCLUDE "win/winsock2.bi"
DIM WinSockData AS LPWSADATA, RetVal AS INTEGER
RetVal = WSAStartup(WINSOCK_VERSION, WinSockData)
IF RetVal > 0 THEN
PRINT RetVal
END IF
Code: Select all
fbc -m test -x .\test.exe test.bas && test
Code: Select all
#INCLUDE "win/winsock2.bi"
DIM WinSockData AS LPWSADATA, RetVal AS INTEGER
RetVal = WSAStartup(WINSOCK_VERSION, WinSockData)
IF RetVal > 0 THEN
PRINT RetVal
END IF
Code: Select all
fbc -m test -x .\test.exe test.bas && test
Code: Select all
#INCLUDE "win/winsock2.bi"
DIM As WSADATA WinSockData
DIM RetVal AS Integer
RetVal = WSAStartup(WINSOCK_VERSION, @WinSockData)
IF RetVal THEN
PRINT "Error: " & RetVal
ELSE
PRINT "No Error"
END If
WSACleanup()
SLEEP
It fails because you declared a WinSockData variable as a pointer type, but didn't point it at anything. I believe FB initializes it to zero by default. So WSAStartup is getting a null pointer and returning an error. Double check the C++ example code. I suspect you'll find it's more like @UEZ's example. You allocate the structure, pass a pointer to that structure, and WSAStartup fills in the structure.Julcar wrote:This little code snippet sends the output 10014 which of course is WSAEFAULT error code. The C/C++ examples on the net has mostly the same code to init windows sockets streams, so I don't know why this fails.
Code: Select all
#INCLUDE "win/winsock2.bi"
DIM WinSockData AS LPWSADATA, RetVal AS INTEGER
DIM AS LPWSADATA WinSockData2
DIM AS INTEGER RetVal2
RetVal = WSAStartup(WINSOCK_VERSION, WinSockData)
IF RetVal > 0 THEN
PRINT "WinSockData value: " & VarPtr(WinSockData)
PRINT RetVal
END IF
RetVal2 = WSAStartup(WINSOCK_VERSION, WinSockData2)
IF RetVal2 > 0 THEN
PRINT "WinSockData2 value: " & VarPtr(WinSockData2)
PRINT RetVal2
END IF
Code: Select all
WinSockData value: 1244912
10014
WinSockData2 value: 1244904
10014
Ohhh I got it!UEZ wrote:Try this:Code: Select all
#INCLUDE "win/winsock2.bi" DIM As WSADATA WinSockData DIM RetVal AS Integer RetVal = WSAStartup(WINSOCK_VERSION, @WinSockData) IF RetVal THEN PRINT "Error: " & RetVal ELSE PRINT "No Error" END If WSACleanup() SLEEP
Code: Select all
declare function WSAStartup(byval wVersionRequested as WORD, byval lpWSAData as LPWSADATA) as long
Code: Select all
type LPWSADATA as WSADATA ptr
Code: Select all
#INCLUDE "win/winsock2.bi"
DIM WinSockData AS WSADATA, RetVal AS INTEGER
RetVal = WSAStartup(WINSOCK_VERSION, VarPtr(WinSockData))
IF RetVal > 0 THEN
PRINT "WinSockData value: " & VarPtr(WinSockData)
PRINT RetVal
END IF
By the way, what you were printing out was a pointer to a (null) pointer.Julcar wrote:Code: Select all
PRINT "WinSockData value: " & VarPtr(WinSockData)