Microsoft Windows CE 3.0  

WSAStartup

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This function initializes a WSADATAstructure.

int WSAStartup(
WORD
wVersionRequested, 
LPWSADATA
lpWSAData
);

Parameters

wVersionRequested
[in] Specifies the highest version of Windows Sockets support that the caller can use. The high order byte specifies the minor version (revision) number; the low-order byte specifies the major version number.
lpWSAData
[out] Long pointer to the WSADATAdata structure that is to receive details of the Windows Sockets implementation.

Return Values

Zero indicates success. To get a specific error value, call WSAGetLastError. The following table shows possible error values.

Value Description
WSASYSNOTREADY The underlying network subsystem is not ready for network communication.
WSAVERNOTSUPPORTED The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation.
WSAEINPROGRESS A blocking Windows Sockets 1.1 operation is in progress.
WSAEPROCLIM The limit on the number of tasks supported by the Windows Sockets implementation has been reached.
WSAEFAULT The lpWSADatais not a valid pointer.

An application cannot call WSAGetLastErrorto determine the error value as is normally done in Windows Sockets is WSAStartupfails. The Winsock.dll will not have been loaded in the case of a failure so the client data area where the "last error" information is stored could not be established.

Remarks

The WSAStartupfunction 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 to retrieve details of the specific Windows Sockets implementation. The application or DLL can only issue further Windows Sockets functions after a successfully calling WSAStartup.

To support future Windows Sockets implementations and applications that can have functionality differences from current version of Windows Sockets, a negotiation takes place in WSAStartup. The caller of WSAStartupand the Winsock.dll indicate to each other the highest version that they can support, and each confirms that the other's highest version is acceptable. Upon entry to WSAStartup, the Winsock.dll examines the version requested by the application. If this version is equal to or higher than the lowest version supported by the DLL, the call succeeds and the DLL returns in wHighVersionthe highest version it supports and in wVersionthe minimum of its high version and wVersionRequested.The Winsock.dll then assumes that the application will use wVersion.If the wVersionfield of the WSADATAstructure is unacceptable to the caller, it should call WSACleanupand either search for another Winsock.dll or fail to initialize.

It is legal and possible for an application written to this version of the specification to successfully negotiate a higher version number than the version of this specification. In such a case, the application is only guaranteed access to higher-version functionality that fits within the syntax defined in this version, such as new Ioctl codes and new behavior of existing functions. New functions, for example, may be inaccessible. To be guaranteed full access to new syntax of a future version, the application must fully conform to that future version, such as compiling against a new header file, linking to a new library, or other special cases.

This negotiation allows both a Winsock.dll and a Windows Sockets application to support a range of Windows Sockets versions. An application can use Winsock.dll if there is any overlap in the version ranges. The following chart gives examples of how WSAStartupworks in conjunction with different application and Winsock.dll versions:

The following code example demonstrates how an application that supports only version 1.1 of Windows Sockets makes a WSAStartupcall:

WORD wVersionRequested; WSADATA wsaData; int err;
wVersionRequested = MAKEWORD( 1, 1 ); 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 1.1.*/ /* Note that if
the DLL supports versions greater */ /* than 1.1 in addition to
1.1, it will still return */ /* 1.1 in wVersion since that is the
version we */ /* requested. */ if ( LOBYTE( wsaData.wVersion ) != 1
|| HIBYTE( wsaData.wVersion ) != 1 ) { /* Tell the user that we
could not find a usable */ /* WinSock DLL. */ WSACleanup( );
return; } /* The WinSock DLL is acceptable. Proceed. */

Once an application or DLL has made a successful WSAStartupcall, it can proceed to make other Windows Sockets calls as needed. When it has finished using the services of the Winsock.dll, the application or DLL must call WSACleanupto allow the Winsock.dll to free any resources for the application.

Details of the actual Windows Sockets implementation are described in the WSADATA structure.

An application or DLL can call WSAStartupmore than once if it needs to obtain the WSAData structure information more than once. On each such call the application can specify any version number supported by the DLL.

An application must call one WSACleanupcall for every successful WSAStartupcall to allow third-party DLLs to make use of a Winsock.dllon behalf of an application. This means, for example, that if an application calls WSAStartupthree times, it must call WSACleanupthree times. The first two calls to WSACleanupdo nothing except decrement an internal counter; the final WSACleanupcall for the task does all necessary resource deallocation for the task.

Requirements

App versions DLL versions wVersion
requested
wVersion wHigh
version
End result
1.1 1.1 1.1 1.1 1.1 use 1.1
1.0 1.1 1.0 1.1 1.0 1.0 use 1.0
1.0 1.0 1.1 1.0 1.0 1.1 use 1.0
1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 1.0 1.1 1.0 1.0 Application fails
1.0 1.1 1.0 --- --- WSAVERNOT
SUPPORTED
1.0 1.1 1.0 1.1 1.1 1.1 1.1 use 1.1
1.1 2.0 1.1 2.0 1.1 1.1 use 1.1
Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winsock.h    
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

WSACleanup, WSADATA