Search code examples
visual-studio-2008visual-c++network-programmingwinsockwinsock2

How to include ws2tcpip.h and ws2def.h into a Visual C++ 2008 project?


I am new to Visual C++. I have installed Visual C++ 2008 Express Edition (with SP1) in Windows XP. I am trying to compile an open source Visual C++ project.

I have open the .vcproj project in VC++ 2008 Express. When I use Build > Rebuild Solution, it shows the following output:

3 error(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

The following are the 3 errors:

error C3861: 'IN6_IS_ADDR_MULTICAST': identifier not found

error C2065: 'IPPROTO_IPV6' : undeclared identifier

error C2065: 'IPPROTO_IPV6' : undeclared identifier

I have been googling for a very long time. I found that these identifier are available in the following files:

  • ws2tcpip.h

  • ws2def.h

  • winsock2.h

If I am not mistaken, these files are used by Windows developers to do network/socket programming. It should be available somewhere in Windows.

May I know what is the difference between error C2065: undeclared identifier and error C3861: identifier not found?

How can I include ws2tcpip.h and ws2def.h into a Visual C++ 2008 project?

Thanks


Solution

  • Is it as simple as #including these headers in the appropriate files?

    #include <winsock2.h>
    #include <ws2tcpip.h>
    

    Note that winsock2.h must be #included before ws2tcpip.h, otherwise you'll get compile errors like "ip_mreq::imr_multiaddr uses undefined struc in_addr" and "Byte is not a member of in6_addr::__unnamed".