未找到 GetAddrInfo 标识符 [英] GetAddrInfo identifier not found

查看:33
本文介绍了未找到 GetAddrInfo 标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译一个 DLL 以在将在 Windows XP 上运行的程序中使用时遇到几个错误.它们都很相似:GetAddrInfo: identifier not found"和FreeAddrInfo: identifier not found".我能做的有限(我必须修改自 2012 年以来未更新的现有代码.我是合作社,所以我的计算机科学学位尚未完成,我可能不知道某些事情).我在静态库中使用 MFC.我的平台工具集是 Visual Studio 2013 - Windows XP (v120_xp).我使用的是 Microsoft Visual Studio Professional 2013.我的 StdAfx.h 包含以下代码:

I'm getting a couple errors when attempting to compile a DLL for use in a program that will run on Windows XP. They are both similar: 'GetAddrInfo: identifier not found', and 'FreeAddrInfo: identifier not found'. I'm limited in what I can do (I must modify existing code that hasn't been updated since 2012. I'm a co-op, so my degree in computer science is not yet complete, and I may not know certain things). I'm using MFC in a static library. My platform toolset is Visual Studio 2013 - Windows XP (v120_xp). I am using Microsoft Visual Studio Professional 2013. My StdAfx.h includes the following code:

#ifndef WINVER
#define WINVER 0x0501
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#define VC_EXTRALEAN
//...
#include <WinSock2.h>

我从中得到错误的 Foo.cpp 文件包含以下标题:

The Foo.cpp file I'm getting the error from includes the following headers:

#include "stdafx.h"
#include <stdio.h>
#include <WinIoctl.h>
#include <process.h>    
#include <Windows.h>
#include <MMSystem.h>
#include <Mstcpip.h>
#include <WS2tcpip.h>

我的 WS2tcpip.h 版本来自 Windows 7.1A SDK.如果我打开它,我可以看到定义了 GetAddrInfo() 和 FreeAddrInfo(),但是无论出于何种原因,VS2013 都找不到这些定义(尽管它可以 找到头文件本身并且没有问题包括他们).

My version of WS2tcpip.h is from the Windows 7.1A SDK. If I open it, I can see that GetAddrInfo() and FreeAddrInfo() are defined, but for whatever reason, VS2013 is not finding those definitions (though it can find the header file itself and has no trouble including them).

附加说明:如果我将 StdAfx.h 中的 #defines 更改为:

Additional note: if I change the #defines in StdAfx.h to:

#define WINVER 0x0600
#define _WIN32_WINNT 0x0600

并使用常规的 Visual Studio 2013 工具集,编译 DLL 没有问题.不幸的是,DLL 必须适用于 Windows XP.我一直无法找到有关为什么会这样的任何信息.我的包含可能在错误的地方吗?

and use the regular Visual Studio 2013 toolset, I have no problems compiling the DLL. Unfortunately, the DLL must work with Windows XP. I've been unable to find any information about why this might be. Could my includes be in the wrong place?

推荐答案

来自 getaddrinfo 文档页面 :

最低支持的客户端 |Windows 8.1、Windows Vista

Minimum supported client | Windows 8.1, Windows Vista

然而:

getaddrinfo 函数已添加到 Windows XP 及更高版本的 Ws2_32.dll 中.

The getaddrinfo function was added to the Ws2_32.dll on Windows XP and later.

您只需要在 SP2 之前的 XP 上使用 getaddrinfo 而不是 GetAddrInfo.在 XP SP2 及更高版本上,您的代码可以正常工作,无需执行任何操作.
作为旁注,ASCII 模式下的 GetAddrInfoGetAddrInfoA 的别名,它实际上是 getaddrinfo 的别名(即使在最近的 Windows 上),所以使用其中一个并不重要.

You just need to use getaddrinfo instead of GetAddrInfo on XP before SP2. On XP SP2 and later, your code just works, nothing to do.
As a side note, GetAddrInfo in ASCII mode is an alias to GetAddrInfoA, which is actually an alias of getaddrinfo (even on recent Windows), so using one or the other doesn't matter.

奖励:

在 XP 之前的版本(例如 Windows 2000)上,您需要包含一个额外的头文件 Wspiapi.h,以模拟 getaddrinfo :

On versions before XP (for example, Windows 2000), You need to include an additional header, Wspiapi.h, to emulate getaddrinfo :

要在早期版本的 Windows 上执行使用此功能的应用程序,您需要包含 Ws2tcpip.h 和 Wspiapi.h 文件.添加 Wspiapi.h 包含文件时,将 getaddrinfo 函数定义为 Wspiapi.h 文件中的 WspiapiGetAddrInfo 内联函数.

To execute an application that uses this function on earlier versions of Windows, then you need to include the Ws2tcpip.h and Wspiapi.h files. When the Wspiapi.h include file is added, the getaddrinfo function is defined to the WspiapiGetAddrInfo inline function in the Wspiapi.h file.

这篇关于未找到 GetAddrInfo 标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆