C++ 如何在win7+;vs2013
我试图使用CreateIpForwardEntry向路由表添加一些规则,有必要在win7上首先调用GetIpInterfaceEntry(请参阅)。以下是我的部分代码:C++ 如何在win7+;vs2013,c++,visual-studio-2013,routetable,C++,Visual Studio 2013,Routetable,我试图使用CreateIpForwardEntry向路由表添加一些规则,有必要在win7上首先调用GetIpInterfaceEntry(请参阅)。以下是我的部分代码: #pragma warning(disable: 4996) #define WIN32_LEAN_AND_MEAN #define _WIN32_WINNT 0x601 //#define _WS2IPDEF_ //#define __IPHLPAPI_H__ #include <windows.h> #in
#pragma warning(disable: 4996)
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x601
//#define _WS2IPDEF_
//#define __IPHLPAPI_H__
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <netioapi.h>
#include <iphlpapi.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#pragma comment(lib, "iphlpapi.lib")
int main() {
typedef DWORD(__stdcall *IPINTENTRY)(PMIB_IPINTERFACE_ROW);// undeclared identifier
MIB_IPINTERFACE_ROW info;
info.InterfaceIndex = 1;
memset(&(info.InterfaceLuid),0,sizeof(info.InterfaceLuid));
info.Family = AF_INET;
HINSTANCE hInst = ::LoadLibrary("Iphlpapi.dll");
IPINTENTRY pFunGetInfEntry = (IPINTENTRY)GetProcAddress(hInst,"GetIpInterfaceEntry");
DWORD dwRet = pFunGetInfEntry(&info);
}
#杂注警告(禁用:4996)
#定义WIN32_精益_和_平均值
#定义_WIN32_WINNT 0x601
//#定义_WS2IPDEF_
//#定义__
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
#pragma注释(lib,“iphlapi.lib”)
int main(){
typedef DWORD(uu stdcall*IPINTENTRY)(PMIB_IPINTERFACE_ROW);//未声明的标识符
MIB_i接口_行信息;
信息接口索引=1;
memset(&(info.InterfaceLuid),0,sizeof(info.InterfaceLuid));
info.Family=AF_INET;
HINSTANCE hInst=::LoadLibrary(“iphlapi.dll”);
IPINTENTRY pfungetingfentry=(IPINTENTRY)GetProcAddress(hInst,“GetIpInterfaceEntry”);
DWORD dwRet=pFunGetInfEntry(&info);
}
代码没有编译,PMIB\u IPINTERFACE\u行是未声明的标识符,我查看了windows标题,控制流的是WS2IPDEF。我定义了它,但现在仍在工作。有人使用过这个功能吗?谢谢。它不是正在编译,还是正在编译但没有运行?为了使代码能够编译,我必须更改includes:I remove
#include <netioapi.h>
#include <iphlpapi.h>
#包括
#包括
并将其替换为
#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#包括
#包括
#包括
在“netioapi.h”顶部的注释之后,按此顺序包括以下标题:
#include <winsock2.h>
#include <windows.h>
#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#include <netioapi.h>
#包括
#包括
#包括
#包括
#包括
#包括
它不再是精益的,只是意味着。并将winsock2的#include移到windows的#include之前。hThanks它在替换这些头文件后工作,并删除_WS2IPDEF_u和IPHLPAPI_H。