MIB_TCPTABLE2结构体使用mingw编译器编译一直提示未定义,已经包含了头文件tcpmib.h。
去mingw目录里找到tcpmib.h,发现有这样的条件编译语句
中间的结构体定义都在里面。说明如果宏定义_WIN32_WINNT大于0x0600才会编译。
在msdn里面找到windows各个的版本_WIN32_WINNT常量定义
//
// _WIN32_WINNT version constants
//
#define _WIN32_WINNT_NT4 0x0400 // Windows NT 4.0
#define _WIN32_WINNT_WIN2K 0x0500 // Windows 2000
#define _WIN32_WINNT_WINXP 0x0501 // Windows XP
#define _WIN32_WINNT_WS03 0x0502 // Windows Server 2003
#define _WIN32_WINNT_WIN6 0x0600 // Windows Vista
#define _WIN32_WINNT_VISTA 0x0600 // Windows Vista
#define _WIN32_WINNT_WS08 0x0600 // Windows Server 2008
#define _WIN32_WINNT_LONGHORN 0x0600 // Windows Vista
#define _WIN32_WINNT_WIN7 0x0601 // Windows 7
#define _WIN32_WINNT_WIN8 0x0602 // Windows 8
#define _WIN32_WINNT_WINBLUE 0x0603 // Windows 8.1
#define _WIN32_WINNT_WINTHRESHOLD 0x0A00 // Windows 10
#define _WIN32_WINNT_WIN10 0x0A00 // Windows 10
// . . 解决办法很简单,就是在包含头文件之前重新定义一下宏
之后在编译警告中发现了重复定义,/i686-5.2.0-release-posix-sjlj-rt_v4-rev1/mingw32/i686-w64-mingw32/include/_mingw.h:225:0,所以原因就确定了, 我用的是windows10LTSC系统,不知道为什么定义成 Windows Vista了!
之后发现在使用函数QueryFullProcessImageName时也有这个问题。使用Mingw编译时候报错
解决办法也是定义系统版本宏高于一定的版本,在windows.h之前。