【发布时间】:2014-09-19 10:10:21
【问题描述】:
我正在尝试使用 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 .我#定义了它,但现在仍在工作。有人用过这个功能吗?谢谢。
【问题讨论】:
-
不再精益,只有卑鄙。并将winsock2 的#include 移到 windows.h 的#include
标签: c++ visual-studio-2013 routetable