You need to call WSAStartup
function to initiate use of the Winsock DLL by a process.
Also, call WSACleanUp
function at the end.
From the link WSAStartup:
The WSAStartup
function must be the first Windows Sockets function called by an
application or DLL. It allows an application or DLL to specify the version of Windows
Sockets required and retrieve details of the specific Windows Sockets implementation.
The application or DLL can only issue further Windows Sockets functions after
successfully calling WSAStartup
.
A good example is also given in the above link.
Also:
An application must call the WSACleanup
function for every successful time the WSAStartup
function is called. This means, for example, that if an application calls WSAStartup
three times, it must call WSACleanup
three times. The first two calls to WSACleanup
do
nothing except decrement an internal counter; the final WSACleanup
call for the task
does all necessary resource deallocation for the task.