#define PORT 5150
#define DATA_BUFSIZE 8192
typedef struct _SOCKET_INFORMATION {
CHAR Buffer[DATA_BUFSIZE];
WSABUF DataBuf;
SOCKET Socket;
WSAOVERLAPPED Overlapped;
DWORD BytesSEND;
DWORD BytesRECV;
} SOCKET_INFORMATION, * LPSOCKET_INFORMATION;
DWORD WINAPI ProcessIO(LPVOID lpParameter);
DWORD EventTotal = 0;
WSAEVENT EventArray[WSA_MAXIMUM_WAIT_EVENTS];
LPSOCKET_INFORMATION SocketArray[WSA_MAXIMUM_WAIT_EVENTS];
CRITICAL_SECTION CriticalSection;
以上数据需要包含文件#include <winsock2.h>
如果包含顺序为:
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include <winsock2.h>
#include "resource.h"
#include "Definition.h"
那么会出现一大堆错误,如下
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(91): warning C4005: “AF_IPX”: 宏重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(460) : 参见“AF_IPX”的前一个定义
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(131): warning C4005: “AF_MAX”: 宏重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(479) : 参见“AF_MAX”的前一个定义
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(168): warning C4005: “SO_DONTLINGER”: 宏重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(402) : 参见“SO_DONTLINGER”的前一个定义
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(212): error C2011: “sockaddr”:“struct”类型重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(485) : 参见“sockaddr”的声明
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(390): error C2059: 语法错误:“常量”
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(390): error C3805: “常量”: 意外标记,应输入“}”或者“,”
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(524): warning C4005: “IN_CLASSA”: 宏重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(287) : 参见“IN_CLASSA”的前一个定义
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(530): warning C4005: “IN_CLASSB”: 宏重定义
1> c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(293) : 参见“IN_CLASSB”的前一个定义
1>c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(536): warning C4005: “IN_CLASSC”: 宏重定义
*
*
*
*
*
*
现在将包含顺序改为:
包含顺序为:
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "Definition.h"
那么将没有任何编译错误。
编译环境:VS2010
#include 报错的问题
2023-12-31 16:58:58