Basically I wanted to know if you can initialize a winsock without creating WSADATA variable or feeding the WSADATA value directly to WSAStartup function?
The call to WSAStartup()
is required, otherwise most Winsock functions will fail with an WSANOTINITIALISED
error. And WSAStartup()
itself requires a pointer to allocated memory to fill in with WSADATA
data. This is not optional.
So, could we not directly define a memory location to store the returned value?
That is exactly what declaring a variable does. But more generally, yes you can certainly pass in any non-NULL memory address, as long as it is a valid memory address within the calling process, and has been allocated to hold at least sizeof(WSADATA)
number of bytes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…