我正在尝试使用CreateIpForwardEntry向路由表添加一些规则,有必要首先在 win7 上调用GetIpInterfaceEntry (请参阅this)。这是我的代码的一部分:
#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);
}
代码无法编译,PMIB_IPINTERFACE_ROW是未声明的标识符,我查看了 Windows 标头,它是控制流程的WS2IPDEF。我#定义了它,但现在仍在工作。有人用过这个功能吗?谢谢。