Answered windows.h and winsock2.h

  • Thursday, May 08, 2008 2:59 PM
     
     
    Following the sample for iocp in the latest SDK (Feb 2008), I tryed to move that code into a DLL project.
    I have to include <windows.h> in order to compile the DLL entry function (something the wizard didn't generate btw), and according to MSDN I need to include <winsock2.h> to make my winsock calls. However, when I compile I get a large amount of redefintion errors originating from conflicts between winsock.h and winsock2.h. Evidently windows.h includes winsock.h.
    What's the deal with these two headers?



All Replies

  • Friday, May 09, 2008 4:08 AM
     
     Answered
    Include <winsock2.h> first, then <windows.h>
  • Saturday, April 04, 2009 2:19 AM
     
     Proposed
    #define _WINSOCKAPI_    // stops windows.h including winsock.h
    #include <windows.h>
    #include <winsock2.h>
    • Proposed As Answer by vvolkman Monday, February 08, 2010 3:43 PM
    •  
  • Monday, February 08, 2010 3:44 PM
     
     
    That solution doesn't work, it yields a different set of errors.
  • Monday, February 08, 2010 4:13 PM
     
     
    If it produces different errors then you need to say which errors.

    But the solution which always works is to include winsock2.h before windows.h.
    Visit my (not very good) blog at http://c2kblog.blogspot.com/
  • Saturday, April 24, 2010 1:55 AM
     
     
    You can also #define WIN32_LEAN_AND_MEAN -- see http://msdn.microsoft.com/en-us/library/ms737629(VS.85).aspx for official details.
  • Monday, April 26, 2010 7:17 PM
     
     
    Have you included ws2_32.lib in your linker?