0

WSAStartup() can be called multiple times in a single process, as long as the requested version is supported by the WinSock dll and that calls to WSAStartup() and WSACleanup() are balanced. In addition to that, Multiple sockets using different WinSock versions is allowed. (see this post: Is it possible to tell if WSAStartup has been called in a process?)

In that case, how do these different WinSock versions coexist?

For example, what if I request the use of a specific WinSock version for my application, and my application also loads a third party dll that happens to request the use a different version? What version gets used, and when?

Guett31
  • 137
  • 12
  • This is covered in the [`WSAStartup()` documentation](https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsastartup) (which I pointed out in my answer to the question you linked to). The first successful `WSAStartup()` loads the WinSock DLL into memory. That call, and all subsequent calls to `WSAStartup()`, are subject to the versions that the loaded DLL supports. Different versions can be requested by each `WSAStartup()` call, as long as the DLL supports them. See the chart in the "Remarks" section of the documentation, it shows which version gets used in each call – Remy Lebeau May 08 '19 at 20:06
  • @Remy Lebeau, my question is more about what version is used when multiple calls to WSAStartup() are made with different versions. Imagine that I call WSAStartup() requesting a specific version in my main application, then I dynamically load a dll whose implementation calls WSAStartup() requesting another version to do its own business. Now I have two WSAStartup() calls, the first one from my main app, and the second from the loaded dll (that I might not even be aware of). At this point, if I create a socket object in my main app, what version of WinSock will be used? – Guett31 May 09 '19 at 16:32
  • "*my question is more about what version is used when multiple calls to WSAStartup() are made with different versions*" - as I have stated several times now, in this question and the other question you linked to, the [`WSAStartup()` documentation](https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsastartup) has the answer you are looking for. Have you tried to read it yet? – Remy Lebeau May 09 '19 at 17:14
  • @Remy Lebeau, I read it before. I just read it again, and there is definitely something I don't get or I missed. I would be grateful if you could point to the section of the documentation that answers my question. Form what I understand, the second call to WSAStartup() from the dll in my example would silently overwrite the first call from the main app, and would switch WinSock to whatever version it requested in the second call. – Guett31 May 09 '19 at 18:46

1 Answers1

0

It says in the MS doc -

An application can call WSAStartup more 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 Winsock DLL.

The last sentence implies, that those subsequent calls don't actually request a different winsock version, just getting the existing one that's saved in wsadata.

If you wanted to change the winsock version in the middle of the program, I suppose you could call WSACleanup (as many times as needed), and "start fresh" with a new WSAStartup

Jay
  • 1,544
  • 22
  • 34