c++ - 如何设置 XAudio2 dll 版本

标签 c++ visual-c++ dll visual-studio-2015 xaudio2

我的 MSVC 2015 C++ 应用程序项目使用 xaudio2.lib。所以 .cvxproj 包含一行

<AdditionalDependencies>xaudio2.lib;%(AdditionalDependencies)</AdditionalDependencies>

查看构建的 .exe,我可以找到一行 XAudio2_8.dll

所以编译器(或链接器)似乎决定只使用 2_8 版本。

导致我的应用程序无法在Windows 7机器上运行的问题,因为那里只安装了较低版本的XAudio2.dll,它找不到XAudio2_8.dll.

那么我该如何修复/修改我的项目,以便生成的 .exe 可以在 Windows 7 上运行?例如,我如何指定使用 XAudio2_7.dll

最佳答案

UPDATE: XAudio 2.9 functionality is now available for Windows 7 SP1, Windows 8, and Windows 10 via the XAudio2Redist. Therefore, you DO NOT NEED the legacy DirectX SDK anymore to target Windows 7 with XAudio2 or if you want xWMA support on Windows 8.x. The code below has been updated for the scenario of when you include the NuGet package.

如果您使用的是 Windows 8.0 SDK 或 Windows 8.1 SDK,则 xaudio2.h header 和 xaudio2.lib 都链接到需要 Windows 8 或 Windows 8 的 XAudio 2.8之后。如果您为 Windows 7 兼容的 exe 正确设置了 _WIN32_WINNT(即 /D _WIN32_WINNT=0x0601/D _WIN32_WINNT=0x0600),那么当您构建您的应用程序时,您会看到构建时失败正是因为 Windows Vista 或 Windows 7 不支持 XAudio 2.8

如果您使用 Windows 10 SDK,则 xaudio2.h header 使用 XAudio 2.9,前提是 _WIN32_WINNT 设置为 0x0A00仅在 Windows 10 上链接到 xaudio2.lib。如果使用 Windows 10 SDK,您可以将 WIN32_WINNT 设置为 0x06020x0603,链接到 xaudio2_8.lib 和它将再次使用 XAudio 2.8。

要支持 Windows 7 SP1 或更高版本,您应该使用 XAudio2Redist,它在 Windows 7 SP1、Windows 8 和 Windows 8.1 上提供 XAudio 2.9 功能。在 Windows 10 上,它会自动转发到 XAudio 2.9 的操作系统版本——如果您只支持 Windows 10,则不需要 XAudio2Redist,因为 XAudio 2.9 是 Windows 10 操作系统的一部分。 NuGet 包包括 xaudio2_9redist.libxapobaseredist.lib

要支持 Windows 7 RTM 或更早版本,您必须使用 legacy DirectX SDK要获取 XAudio 2.7 header ,您必须使用 legacy DirectSetup 部署 XAUDIO2_7.DLL包裹。由于 header 与 Windows 8.x SDK 和 Windows 10 SDK 冲突,除了需要正确设置项目包含路径之外,实际上最好对旧版 Direct SDK header 进行完整路径引用。

例如,DirectX 音频工具包 DX11/DX12 Audio.h header 中包含以下内容:

#if defined(USING_XAUDIO2_REDIST) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
#define USING_XAUDIO2_9
#elif (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
#define USING_XAUDIO2_8
#else
#define USING_XAUDIO2_7_DIRECTX
#endif

#if defined(USING_XAUDIO2_8) || defined(USING_XAUDIO2_9)
#include <xaudio2.h>
#include <xaudio2fx.h>
#include <x3daudio.h>
#include <xapofx.h>

#ifndef USING_XAUDIO2_REDIST
#if defined(USING_XAUDIO2_8) && defined(NTDDI_WIN10)
#pragma comment(lib,"xaudio2_8.lib")
#else
#pragma comment(lib,"xaudio2.lib")
#endif
#endif
#else // USING_XAUDIO2_7_DIRECTX
// Using XAudio 2.7 requires the DirectX SDK
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\comdecl.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2fx.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xapofx.h>
#pragma warning(push)
#pragma warning( disable : 4005 )
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\x3daudio.h>
#pragma warning(pop)
#pragma comment(lib,"x3daudio.lib")
#pragma comment(lib,"xapofx.lib")
#endif

参见 Adding the DirectX Tool Kit for Audio , XAudio2 and Windows 8 , Known Issues: XAudio 2.7 , 和 Using the Windows Headers .

关于c++ - 如何设置 XAudio2 dll 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456002/

相关文章:

C++/CLI 中的正则表达式用法

c++ - 如何清除 C++ 数组?

dll - Azure:在工作角色中使用框架/SDK(带有 .dll)的最佳实践

c++ - 如何在 UML 类图中表示纯虚函数?

c++ - 如何迭代 std::list<AbstractType*>

c++ - CMake 无法找到 boost_asio

c++ - 为 Visual Studio 2012 (ARPACK) 使用 dllwrap 生成 .dll 文件

c++ - 使用getline连续输入行到txt文档的结尾C++

c++ - 来自一个 dll 的函数调用另一个 dll 的同名函数

.net - 解压DLL后重新注册DLL问题