Winsock(微軟套接字接口)的使用(2)

(2)Initializing Winsock

Before calling Winsock functions we must initialize the use of the winsock DLL.


①Create a WSADATA object called wsaData
②Call WSAStartup and return its value as an integer and check for errors.

WSADATA wsadata;

int iResult;

// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
    printf("WSAStartup failed: %d\n", iResult);
    return 1;
}

Node: The WSAStartup function is called to initiate use of WS2_32.dll. The WSADATA structure contains information about the Windows Sockets implementation. The MAKEWORD(2,2) parameter of WSAStartup makes a request for version 2.2 of Winsock on the system, and sets the passed version as the highest version of Windows Sockets support that the caller can use.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章