# DirectX SDK去哪了？

听说DirectX11出了很多新特性，于是根据经验到网上去找SDK来体验，结果资源并不多，好不容易找到了，竟然安装失败，错误代码“S1023”于是到微软官网上找，好不容易找到了“DXSDK_Mar09”，下下来安装还是失败。于是反过头查S1023是何意。一查，竟是因为系统中存在更高版本的DirectX。嗯我这Win7以前可没专门装过DirectX11呀。于是又到官网上翻，终于看到了一篇“Where is the DirectX SDK?”。看完全文方知究竟。现将主要条款翻译如下：

DirectX现在是Windows重要的组成部分。因为WindowsSDK是Windows主要的开发用SDK，（从Windows8起，DirectX已成为WindowsSDK的一部分），所以你下了最新WinSDK就有了最新的DirectX SDK。也就是你装了VS2012或者VS2013就有了新版的D3DXSDK了。

不过D3DX并不是WindowsSDK的基本使用API，所以你若要使用D3DXSDK开发DirectX程序，你就得如下操作（以下是原文中的第5步到第10步，就是项目的属性设置啦，我就不费劲了。）:

1. Modify the project’s VC++ directories as follows to use the right order for SDK headers and libraries.

按如下步骤修改项目（属性中）的“VC++目录”以便调用SDK的头文件与库文件
i. Open Properties for the project and select the VC++ Directories page.
打开项目的属性并选择“VC++目录”页
ii. Select All Configurations and All Platforms.
选择“所有配置”和“所有平台”
iii. Set these directories as follows:
设置如下这些目录
• Executable Directories: <inherit from parent or project defaults> (On right-side drop-down)
• 可执行（文件）目录：从父级或项目默认目录继承
• Include Directories: $(IncludePath);$(DXSDK_DIR)Include
• 包含目录：$(IncludePath);$(DXSDK_DIR)Include
• Include Library Directories: $(LibraryPath);$(DXSDK_DIR)Lib\x86
• 库目录：$(LibraryPath);$(DXSDK_DIR)Lib\x86
iv. Click Apply.
v. Choose the x64 Platform.
vi. Set the Library Directory as follows:
• Library Directories: $(LibraryPath);$(DXSDK_DIR)Lib\x64
2. Wherever "d3dx9.h", "d3dx10.h", or "d3dx11.h" are included in your project, be sure to explicitly include "d3d9.h", "d3d10.h" and "dxgi.h", or "d3d11.h" and "dxgi.h" first to ensure you are picking up the newer version. You can disable warning C4005 if needed; however, this warning indicates you are using the older version of these headers.
3. Remove all references to DXGIType.h in your project. This header doesn't exist in the Windows SDK, and the DirectX SDK version conflicts with the new winerror.h.
4. All D3DX DLLs are installed onto your development computer by the DirectX SDK installation. Ensure that the necessary D3DX dependencies are redistributed with any sample or with your application if it is moved to another machine.
5. Be aware that replacement technologies for current uses of D3DX11 include DirectXTex and DirectXTK. D3DXMath is replaced byDirectXMath.
1. Ensure that you are using the new version of the HLSL shader compiler by observing the following conditions:

1. Changing the executable directory as per step 5 will cause project builds to use FXC from the Windows SDK install. Be aware that HLSL files are now officially recognized by Visual Studio. You can add them as project files and set compiler options through the project system.

2. Invoking run-time compilation through the legacy D3DX DLL will use the incorrect older version of the HLSL compiler. Replace all references to D3DXCompile*, D3DX10Compile*, and D3DX11Compile* APIs in your code with the D3DCompile function in D3DCOMPILER_46.DLL or D3DCOMPILER_47.DLL.

3. Any project that uses run-time shader compilation must have D3DCOMPILER_xx.DLL copied to the local executable path for the project. This DLL is available in this sub-directory of the Windows SDK installation under %ProgramFiles(x86)%\Windows Kits\8.0\Redist\D3D\<arch> or %ProgramFiles(x86)%\Windows Kits\8.1\Redist\D3D\<arch> where <arch> is x86 and x64.

The D3DCOMPILER_46.DLL or D3DCOMPILER_47.DLL from the Windows SDK is not a system component and should not be copied to the Windows system directory. You can redistribute this DLL to other computers with your application as a side-by-side DLL.

2. Any project that uses the XInput API and is intended to run on Windows 7 or older versions of Windows need to use either the legacy version (9.1.0) or will need to explicitly include the headers and libraries for this component from the DirectX SDK. The XInput header and XINPUT.LIB that are included in the Windows SDK target only the version (1.4) that ship as part of Windows 8 and later. The same header can be used with XINPUT9_1_0.LIB to use the legacy version, which is included with older versions of Windows. The legacy version of XInput doesn't detect full capabilities or support controller-integrated audio, so if support for these features is required, you must use the DirectX SDK version (1.3).

To use the full-featured down-level XInput API, you should #include the specific XInput headers from the DirectX SDK directly:

#include <%DXSDK_DIR%Include\xinput.h>

%DXSDK_DIR%Include\<arch>\xinput.lib

The XINPUT1_3.DLL binary is installed to the Windows system directories by the DirectX SDK installation on your development computer. You will need to redistribute this binary with your application using the DirectX Setup installation from the DirectX SDK.

3. Any project that uses the XAudio2 API and is intended to run on Windows 7 or older versions of Windows need to use either the older version (9.1.0) or explicitly include the headers and libraries for this component from the DirectX SDK. The XAudio2 headers and libraries that are included with the Windows SDK target only the version (2.8) that is included as part of Windows 8.

For example, with XAudio2, you should #include the specific XAudio2 headers from the DirectX SDK directly:

#include <%DXSDK_DIR%Include\xaudio2.h>

%DXSDK_DIR%Include\<arch>\xaudio2.lib

The XAUDIO2_7.DLL binary is installed to the Windows system directories by the DirectX SDK installation on your development computer. You need to redistribute these libraries with your application using the DirectX Setup installation from the DirectX SDK.

4. If you’ve used the DirectX SDK with past versions of Visual Studio, the Visual Studio 2010 upgrade might have migrated the DirectX SDK path into your default project settings. It is recommended that you remove these settings to prevent future build errors. In the%USERPROFILE%\AppData\Local\Microsoft\MSBuild\v4.0 directory, modify the Microsoft.Cpp.Win32.user and Microsoft.Cpp.x64.userfiles to remove all references to DXSDK_DIR paths. Alternatively, you can remove the entire <PropertyGroup> node that contains the Path entries such as <ExecutablePath> and <IncludePath> to revert to standard defaults. If you don’t see references to DXSDK_DIR in these files, no changes are necessary.

5. If the resulting app supports Windows Vista with Service Pack 2 (SP2) as well as Windows 7 and Windows 8 and later, set the Preprocessor Definition named _WIN32_WINNT to 0x600. If it only supports Windows 7 and Windows 8 and later, set it to 0x601.

For example:

1. Open Properties for the project and select C/C++ > Preprocessor.
2. Select All Configurations and All Platforms.
3. Go to the Preprocessor Definitions section and set _WIN32_WINNT=0x600.
4. Click Apply