MSDN Docs

WSACleanup

Synopsis

int WSACleanup(void);

Terminates use of the Winsock DLL (Ws2_32.dll). After calling WSACleanup, no Winsock functions may be called except for another call to WSAStartup.

Return Value

ValueMeaning
0Success.
SOCKET_ERRORFailure. Call WSAGetLastError for extended error information.

Remarks

Example

#include <winsock2.h>
#include <stdio.h>

int main(void) {
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
        printf("WSAStartup failed\\n");
        return 1;
    }

    // ... use Winsock ...

    int result = WSACleanup();
    if (result == SOCKET_ERROR) {
        printf("WSACleanup failed: %d\\n", WSAGetLastError());
    } else {
        printf("Winsock cleaned up successfully\\n");
    }
    return 0;
}

See Also