2

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?

Nick
  • 3,205
  • 9
  • 57
  • 108

1 Answers1

6

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 (i.e. /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.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • 1
    Links need to be updated due to the blog content getting moved to github: [XAudio2 and Windows 8](https://walbourn.github.io/xaudio2-and-windows-8/). [Known Issues: XAudio 2.7](https://walbourn.github.io/known-issues-xaudio-2-7/). – kornman00 Aug 21 '19 at 23:59
  • Hi, this seems like a good place to make a comment. It looks like Microsoft dropped the ball with the 3D stuff. They included the x3daudio.h in the include directory for Win 10 but forgot the libraries. Use C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\ x64 or x86 for the missing X3DAudio.lib and XAPOFX.lib. I made my own directory for those as the dll was already in the DX9 redistributable. – developer68 Apr 27 '20 at 16:57
  • ``x3daudio.lib`` and ``xapofx.lib`` are not needed for XAudio 2.8 or later. Those entry-points are already in the ``xaudio2.lib``. – Chuck Walbourn Apr 27 '20 at 19:17
  • Technical aside: XAudio 2.7 used "COM initialization" so for this version ``XAudio2Create`` was an inline wrapper around ``CoCreateInstance`` so there was no ``xaudio2.lib``. With XAudio 2.8 or later, it doesn't use COM and instead the ``XAudio2Create`` entry is in ``xaudio2.lib``. Since there was already an import library, we just added the content from ``x3daudio.lib`` and ``xapofx.lib`` to the one library. In all versions of XAudio2, there's a distinct helper ``xapobase.lib`` library for writing custom xAPOs. – Chuck Walbourn Apr 27 '20 at 19:47
  • @ChuckWalbourn [microsoft](https://learn.microsoft.com/en-us/windows/win32/xaudio2/xaudio2-versions#xaudio-28-windows-8x) says that (at least for XAudio 2.8) we need to link `XAUDIO2_8.LIB` which now is a 1-package-all XAudio2, X3DAudio and XPOFX interface. – KeyC0de Oct 20 '20 at 12:08
  • @Nikos - good catch. The code above had assumed you were using Windows 8 SDK to build for XAudio 2.8 for Windows 8--which was still true when I supported VS 2013. For the Windows 10 SDK, you have to use xaudio2_8.lib. – Chuck Walbourn Oct 20 '20 at 19:50