Re: Error in WS2DETECT routine?

Giganews Newsgroups
Subject: Re: Error in WS2DETECT routine?
Posted by:  Remy Lebeau (TeamB) (gambit…
Date: Tue, 29 Jul 2003

"Scott Bussinger" <scot…> wrote in message

> If I'm reading the documentation for WSAStartup correctly,
> this routine this requests that you'd like to access Winsock
> version 16.16.

Although I do agree that it is a typo, it is still a valid request in
general.  It is perfectly valid for the caller to request a version number
that is higher than the socket's implementations actual available version.
The whole point of WSAStartup(), besides intializing the DLL, is for the app
and WinSock DLL to negotiate versions between each other.  According to the
WSAStartup() documentation:

        [in] The highest version of Windows Sockets support that the
***caller can use***.

    In order to support future Windows Sockets implementations and
applications which may have functionality differences from current version
of Windows Sockets, a negotiation takes place in WSAStartup. The caller of
WSAStartup and the Windows Sockets 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 Windows Sockets 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 wHighVersion the highest
version it supports and in wVersion the minimum of its high version and

> The routine then ignores any error codes from the WSAStartup call
> and looks at the returned data to decide what's there.

That is fine.

> No where in the function documentation that I can see does it
> say that the contents of Data are valid if an error is returned.

Perhaps not, but they do specify that the call will succeed if the caller
specify a higher version than the DLL actually supports, and that the DLL
will return the version it actually implements.

> Also I don't think WSACleanup should be called if WSAStartup isn't

Agreed, although even if WSAStartup() failed, WSACleanup() will simply

> The code in IdStackWindows uses $202 for the version check and that
> makes perfect sense as Winsock version 2.2. I think what the code for
> the test should be doing is using $101 for the version check

Actually, I would think that IsW32Avail() should be testing for 2.2 since
the rest of Indy uses 2.2 anyway, not 1.1.  If not, then it will be possible
to run IsW32Avail() on an older machine where 1.1 is available and thus
returns true, but then IdStackWindows fails later because 2.2. is not
available afterall.



In response to

Error in WS2DETECT routine? posted by Scott Bussinger on Tue, 29 Jul 2003