简体   繁体   中英

How to set XAudio2 dll version

My MSVC 2015 C++ application project uses xaudio2.lib . So the .cvxproj contains a line

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

Looking into .exe built, I can find a line XAudio2_8.dll .

So it seems that the compiler (or the linker) has decided to use just 2_8 version.

It leads to a problem that my app cannot be run on Windows 7 machine, because only lower versions of XAudio2.dll are installed there, and it cannot find XAudio2_8.dll .

So how can I fix/modify my project so that the resulting .exe can be run on Windows 7? How can I specify to use XAudio2_7.dll , for instance?

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.

If you are using the Windows 8.0 SDK or Windows 8.1 SDK, then the xaudio2.h headers and xaudio2.lib all link to XAudio 2.8 which requires Windows 8 or later. If you had set _WIN32_WINNT correctly for a Windows 7 compatible exe (ie /D _WIN32_WINNT=0x0601 or /D _WIN32_WINNT=0x0600 ) then when you built your application you would have seen a build-time failure precisely because XAudio 2.8 is not supported for Windows Vista or Windows 7

If you use the Windows 10 SDK, then the xaudio2.h header uses XAudio 2.9 if _WIN32_WINNT is set to 0x0A00 which works when linked against xaudio2.lib on Windows 10 only. If using the Windows 10 SDK, you can set WIN32_WINNT to 0x0602 or 0x0603 , link against xaudio2_8.lib and it will again use XAudio 2.8.

To support Windows 7 SP1 or later, you should use the XAudio2Redist which provides XAudio 2.9 functionality on Windows 7 SP1, Windows 8, and Windows 8.1. On Windows 10 it automatically forwards to the OS version of XAudio 2.9--if you are only supporting Windows 10 you don't need the XAudio2Redist since XAudio 2.9 is part of the Windows 10 OS. The NuGet package includes xaudio2_9redist.lib and xapobaseredist.lib .

To support Windows 7 RTM or earlier, you have to use the legacy DirectX SDK to get the XAudio 2.7 headers, and you must deploy XAUDIO2_7.DLL using the legacy DirectSetup package. Because of the header conflicts with the Windows 8.x SDK and Windows 10 SDK, it's actually best to do a full-path reference to the legacy Direct SDK headers in addition to needing to set up the project include paths correctly.

For example, DirectX Tool Kit for Audio DX11 / DX12 has the following in the 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM