高分求答,关于getiftable()和getifentry(),急急急!!!!!!

painkiller 2005-06-06 06:33:24
我的程序里调用了getiftable和getifentry(),但是编译的时候提示错误为

interface error LNK2019: 无法解析的外部符号 _GetIfEntry@4 ,该符号在函数 "char * __cdecl if_nametoindex(unsigned int,char *)" (?if_nametoindex@@YAPADIPAD@Z) 中被引用

interface error LNK2019: 无法解析的外部符号 _GetIfEntry@4 ,该符号在函数 "unsigned int __cdecl if_nametoindex(char const *)" (?if_nametoindex@@YAIPBD@Z) 中被引用


谁能告诉我这是为什么啊??我下了微软的server 2003 sdk,装上以后仍旧不可以使用。
有谁在windows xp下能调用这两个函数吗??


其中一个文件的代码如下:::

#include "stdafx.h"
#include "iphlpapi.h"
#include "windows.h"


struct if_nameindex {
unsigned int if_index; /*1, 2,…*/
char* if_name; /*null terminated name:”le0”, …*/
};
struct if_nameindex* if_nameindex(void)
{
// Declare and initialize variables.
PMIB_IFTABLE ifTable;
PMIB_IFROW pMibIfRow;
DWORD dwSize = 0;
DWORD dwRetVal = 0;
struct if_nameindex *result,*ifptr;


// Allocate memory for our pointers.
ifTable = (MIB_IFTABLE*) malloc(sizeof(MIB_IFTABLE));
pMibIfRow = (MIB_IFROW*) malloc(sizeof(MIB_IFROW));

// Before calling GetIfEntry, we call GetIfTable to make
// sure there are entries to get.

// Make an initial call to GetIfTable to get the
// necessary size into dwSize
if (GetIfTable(ifTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
GlobalFree(ifTable);
ifTable = (MIB_IFTABLE *) malloc (dwSize);
}
// Make a second call to GetIfTable to get the actual
// data we want.
if ((dwRetVal = GetIfTable(ifTable, &dwSize, 0)) == NO_ERROR) {
if (ifTable->dwNumEntries > 0) {
if ( (ifptr =(struct if_nameindex *) malloc(dwSize)) == NULL) /* overestimate */
return(NULL);

for(unsigned int i=1;i<=ifTable->dwNumEntries;i++){
pMibIfRow->dwIndex=i;
if ((dwRetVal = GetIfEntry(pMibIfRow)) == NO_ERROR) {
ifptr->if_index=i;
ifptr->if_name=(char*)pMibIfRow->wszName;

}
ifptr++;
}
ifptr->if_index=0;
ifptr->if_name=NULL;
result=ifptr;

}
else {
printf("GetIfEntry failed.\n");
return 0;
// Here you can use FormatMessage to find out why
// it failed.
}



}
else {
printf("\tGetIfTable failed.\n");
return 0;
}
free(ifTable);
return(result);

}
void if_freenameindex(struct if_nameindex *ptr)
{
free(ptr);
}
...全文
323 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧