c++ - 在 Visual Studio 2012 中使用 DirectX 11

标签 c++ visual-studio-2012 directx directx-11

我尝试在我的 C++ 项目中使用 DirectX 11,但是当我编译时出现错误:

D3D11 ERROR: D3D11 header version mismatch.
The application was compiled against and will only work with D3D11_SDK_VERSION (1), but the currently installed runtime is version (7).
Recompile the application against the appropriate SDK for the installed runtime.

我不知道是什么原因造成的。有没有办法切换它尝试编译的运行时?我从 2010 年 6 月开始安装了 DirectX SDK。我尝试按照 Microsoft 的说明进行操作 (http://msdn.microsoft.com/en-us/library/windows/desktop/ee663275(v=vs.85).aspx) 以确保使用 DirectX 的设置正确。但我仍然收到此错误。有谁知道可能导致此问题的原因以及如何解决它?我使用的是 Windows 8 64 位和 Visual Studio 2012。

供引用

我将其作为一个空的 C++ 解决方案开始,而不是作为 DirectX 应用程序。以下是我的代码中处理 DirectX 的部分

#include <amp.h>
#include <amp_math.h>
#include <amp_graphics.h>
#include <d3d11.h>
#include <dxgi.h>

#pragma comment(lib, "d3d11")
#pragma comment(lib, "dxgi")

// Inside main()
    IDXGIAdapter* pAdapter = nullptr; // Use default adapter

    unsigned int createDeviceFlags = D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT;
    ID3D11Device *pDevice = nullptr;
    ID3D11DeviceContext *pContext = nullptr;
    D3D_FEATURE_LEVEL featureLevel;
    HRESULT hr = D3D11CreateDevice(pAdapter,
                                    D3D_DRIVER_TYPE_UNKNOWN,
                                    NULL,
                                    createDeviceFlags,
                                    NULL,
                                    0,
                                    D3D11_SDK_LAYERS_VERSION,
                                    &pDevice,
                                    &featureLevel,
                                    &pContext);
    if(FAILED(hr) ||
        ((featureLevel != D3D_FEATURE_LEVEL_11_1) &&
        (featureLevel != D3D_FEATURE_LEVEL_11_0)))
    {
        std::wcerr << "Failed to create Direct3D 11 device" << std::endl;
        return 10;
    }

最佳答案

您需要使用文档 here 中的 D3D11_SDK_VERSION 来代替 D3D11_SDK_LAYERS_VERSION .

关于c++ - 在 Visual Studio 2012 中使用 DirectX 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13785431/

相关文章:

c++ - 对于单元测试,是否有一种骇人听闻的方法来更改 const 变量的值?

c++ - 在这种情况下,我如何在选择时强制进行 C++ 宏替换?

c++ - 如何返回 lambda 对象?

visual-studio-2010 - 为什么vs2012不支持XNA?

c++ - 模糊的天空盒纹理

c++ - 函数 undefined reference C++

c++ - 大小为 1 的 char 数组和 strcat 的问题

windows - 在 VS 2012 Windows 7 中设置 Windows SDK

c++ - 在C++/Directx中使用EXACT进行简单的2D游戏

c++ - 恢复调试 session 不构建更改 VS2012