12

I am confused about couple of things about winsock.

First, what the difference between including Winsock2.h vs winsock2.h (caps of 'w')

Second, what is the difference between linking with wsock32.lib with ws2_32.lib?

I have tried couple of combinations and they result in compile time errors. Can anyone explain me the logical reasoning behind what to use?

Thanks Nick

Nick
  • 1,692
  • 3
  • 21
  • 35

2 Answers2

15

There is no difference between Winsock2.h and winsock2.h. Filenames are case-insensitive on typical Windows filesystems. The ws2_32.lib file is for Winsock 2, while wsock32.lib is for the obsolete, older version.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • 1
    Addendum: Winsock 2 (ws2_32.lib) is an extension to Winsock 1 (wsock32.dll). A program that currently works against wsock32.dll should still work fine when relinked against ws2_32.dll. – Lucio Paiva May 18 '14 at 00:22
  • The HawkNL multicast example (hawksoft.com/hawknl) doesn't work when linking with ws2_32.lib, but will work with wsock32.lib. However, once you update the #include's to match the new library becomes , etc., things begin to work again. – Rob Bryce Apr 10 '15 at 19:56
7

As shown here: https://technet.microsoft.com/en-us/library/cc958787.aspx, wsock32.dll and wsock.dll are the backwards-compatiblity shells for w2_32.dll

You can use wsock32.dll for compatibility with Win95, or wsock.dll for compatibility with win3.11 :) But normally they are used by Win95 and Win3.11 programs for compatibility with win2K+

wsock32.lib and w2_32.lib contain a list of the exported functions and data elements from the dynamic link libraries.

Note: some of the differences between wsock32 and ws_32 may be unexpected. For example wsock32 will run winsock version 2.2 API -- but to get version 2.0 you need w2_32.

david
  • 2,435
  • 1
  • 21
  • 33