【问题标题】:How to use GetIpInterfaceEntry on win7+vs2013如何在win7+vs2013上使用GetIpInterfaceEntry
【发布时间】: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


【解决方案1】:

是不编译,还是编译不运行?要编译代码,我必须更改包含:我删除了

#include <netioapi.h>
#include <iphlpapi.h>

替换为

#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>

遵循“netioapi.h”顶部的 cmets。

【讨论】:

  • 感谢它在替换这些标头并删除 _WS2IPDEF_IPHLPAPI_H 后工作。
【解决方案2】:

按此顺序包含以下标题:

#include <winsock2.h>
#include <windows.h>
#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#include <netioapi.h>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    • 2011-08-27
    • 1970-01-01
    相关资源
    最近更新 更多