开发者

structure repetition error compiling C WinSock code in visual studio 2010

I have been trying to compile C source code in visual studio 2010. While compiling i am getting some errors like:

  1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(4277): error C2040: 'CONTEXT' : '_CONTEXT' differs in levels of indirection from 'binding *'
  1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winuser.h(5341): error C2365: 'INPUT' : redefinition; previous definition was 'enumerator'
  1>c:\documents and settings\xyz\desktop\abc\clause.h(72) : see declaration of 'INPUT'
  1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
  1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h(176) : see declar开发者_StackOverflow社区ation of 'timeval'

I searched for those error and but some hints that it is due to the change in order of the header files. But could not get the exact answer. May I know , How can I overcome this problem?

Following is the order of header file inclusions.

 #include <WinSock2.h>  
 #include <Windows.h>
 #include <stdio.h>

Thanks in advance.


See here - if you include windows.h explicitly with winsock2.h you have to add a #define WIN32_LEAN_AND_MEAN to make this work.

For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜