Installing DirectX with Wix
Note: If you're targeting the version of DirectX that comes with the Windows 8 SDK, you should simply have your installer put relevant DirectX DLLs in the application's target directory. See here .
When trying to run a DirectX application on a computer other than the one you initially developed it on, you've probably had to deal with the program complaining about not being able to find DirectX related dll files. Although major DirectX releases (9, 10, 11) only take place rarely, features do get added through a version's lifespan, resulting in SDK versions such as 'June 2010' (end-user runtime, SDK). When building an application with a specific SDK version, your users will need the dll files (D3DX and compiler ones in particular) that belong to that specific release.
Although many programs (such as games) just include a complete DirectX redistributable installation and launch it as a separate step after the normal installation, there's a better way. Looking at the unpacked redistributable that comes with the SDK (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Redist), there's nearly 100MB of files that go back to 2005-era SDK releases; let's just install the ones that are required, seamlessly integrated in the main install.
Thanksfully, Microsoft provides a simple API to do just that. The DirectSetup documentation page describes which files to distribute, and functions to copy/install the files. To summarize, the following files are always required:
What else is required depends on the SDK version you're using and which DirectX libraries your program builds on. For each SDK version, there are library files for:
- The HLSL Compiler (D3DCompiler), x86 and x64 versions
- DirectCompute (d3dcsx), x86 and x64 versions
- D3DX9, x86 and x64 versions
- D3DX10, x86 and x64 versions
- D3DX11, x86 and x64 versions
- Cross-platform Audio Creation Tool (XACT), x86 and x64 versions
- DirectX Audio (XAudio), x86 and x64 versions
The DirectSetup API is quite simple. It installs/updates DirectX (which shouldn't done by hand) and doesn't provide any means to remove files; you're not supposed to. Really only two functions matter:
DirectXSetup which installs the files, and
DirectXSetupSetCallback, which allows a callback function to be set to track installation progress. This callback function receives information on the stage of the setup process (initializing, copying, etc) and which file is being worked on.
The Wix project
So we know which files to install, and that there are functions meant to install them. Clearly, this'll be a job for a custom action, but lets look at the installer first. As a demo project, let's make a simple installer that just updates the graphics related components of DirectX to the June 2010 versions. First, a .wxs file that contains the DirectX components: