Initializing and Cleaning Up
Windows socket implementations must be initialized before the socket API can be used by the Networking package and must be cleaned up when the application exits. The RWWinSockInfo class simplifies these processes. Its constructor performs the initialization tasks and its destructor performs the termination tasks.
To use this class, declare an instance of RWWinSockInfo in a scope that encloses all of the Networking package calls. Usually, instantiating one of these objects in the main() or WinMain() portion of your application is sufficient.
 
int main()
{
RWWinSockInfo sockApiInit; //1
...
} //2
or
 
int PASCAL WinMain(HINSTANCE, HANDLE, LPSTR, int)
 
{
RWWinSockInfo sockApiInit; //1
...
} //2
//1 Invokes the RWWinSockInfo constructor, which initializes the socket API.
//2 sockApiInit was the first named object constructed, so it is the last destroyed. It ensures that no other Networking package calls are required for the application. It allows the socket implementation to free any resources associated with the application.
NOTE: If you use Windows and you plan to use any Networking package objects in a DLL, you must create a custom DLLMAIN() function, and you must create an instance of the RWWinsockInfo class in that function.