The WSADATA structure contains information about the Windows Sockets implementation.
typedef struct WSAData {
WORD wVersion; // Version of the Windows Sockets
WORD wHighVersion; // Highest version of the Windows Sockets
char szDescription[WSADESCRIPTION_LEN+1]; // description of the Windows Sockets implementation. The text (up to 256 characters in length) char szSystemStatus[WSASYS_STATUS_LEN+1]; // relevant status or configuration information
unsigned short iMaxSockets; // ignore
unsigned short iMaxUdpDg; // ignore
char FAR* lpVendorInfo; // ignore
} WSADATA, *LPWSADATA;
Note An application should ignore the iMaxsockets, iMaxUdpDg, and lpVendorInfo members in WSADATA if the value in wVersion after a successful call to WSAStartup is at least 2.
当前的实际用法是:
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
return 0;
} // 但是变量wsaData再也没有出现过,代码还不能删除,
Example Code
The following example demonstrates the use of the WSADATA structure.
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
本文介绍了WSADATA结构,它是Windows Sockets实现中包含的关键信息。文章通过示例代码展示了如何使用WSADATA结构验证Windows Sockets DLL是否支持所需版本,并检查版本号。

1万+

被折叠的 条评论
为什么被折叠?



