c++ - 未找到 GetAddrInfo 标识符

标签 c++ visual-studio-2013 mfc

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

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

我收到错误的 Foo.cpp 文件包含以下 header :

#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 找不到这些定义(尽管它可以找到头文件本身并且没有任何问题包括他们)。

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

#define WINVER 0x0600
#define _WIN32_WINNT 0x0600

并使用常规的 Visual Studio 2013 工具集,我编译 DLL 没有任何问题。不幸的是,DLL 必须在 Windows XP 上工作。我一直无法找到任何有关原因的信息。我的包含内容可能位于错误的位置吗?

最佳答案

来自getaddrinfo documentation page :

Minimum supported client | Windows 8.1, Windows Vista

但是:

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 上也是如此),所以使用其中之一并不重要。

奖金:

在 XP 之前的版本(例如 Windows 2000)上,您需要包含一个附加 header Wspiapi.h,以模拟 getaddrinfo:

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.

关于c++ - 未找到 GetAddrInfo 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36429384/

相关文章:

c++ - 计算投影到地球上的圆上的点

c++ - 使用 Eigen 库运行 UmfPackLU<> 时 Appcrash

c++ - 为什么我的 Win32(c++, visual studio 2013) 窗口没有出现?

azure - 无法初始化 Windows Azure 存储模拟器。无法启动存储模拟器

c++ - 为什么 CMFCMenuBar 没有使用快捷键表?

c++ - 以编程方式完全删除 MFC 工具栏中的按钮

c++ - 函数需要抽象类型 A 的 C++ 对象。如何将 A 子类的 Lua 对象传递给它?

c++ - 如何从 pqxx 调用重载的远程过程

sdk - VS 2013 和 Lync sdk 2013

c++ - CPrintDialog::OnInitDialog 不会每次都被调用