X1507 Visual Studio 2015 无法打开源文件:"Windows.h"

X1507 Visual Studio 2015 Failed to open source file: "Windows.h"

我正在尝试学习 DirectX 11,目前正在研究光照。我需要在场景中添加定向光,但是当我设置我的 LightHelper.h 文件时,它拒绝编译。它抛出错误 X1507 "failed to open source file: Windows.h".

我已经尝试卸载 Windows SDK 并重新配置一些包含选项,但均无济于事。这是 header 文件的代码。

    #pragma once

    #include <Windows.h>
    #include <DirectXMath.h>

    struct DirectionalLight
    {
        DirectionalLight()
        {
            ZeroMemory(this, sizeof(this));
        }

        DirectX::XMFLOAT4 Ambient;
        DirectX::XMFLOAT4 Diffuse;
        DirectX::XMFLOAT4 Specular;
        DirectX::XMFLOAT3 Direction;
        float Pad;
    };

    struct Material
    {
        Material()
        {
            ZeroMemory(this, sizeof(this));
        }

        DirectX::XMFLOAT4 Ambient;
        DirectX::XMFLOAT4 Diffuse;
        DirectX::XMFLOAT4 Specular;
        DirectX::XMFLOAT4 Reflect;
    };

这不是唯一 header 文件(当然)有 Windows.h,但所有其他 link 都没有问题...我一直在努力现在弄清楚几天。挺烦人的。

谢谢

编辑:这些是我尝试过的解决方案。

Cannot open Windows.h

https://software.intel.com/en-us/articles/error-cannot-open-source-file-windowsh-in-gfx-sampleszip-shipped-with-intelr-c-compiler-150

我也尝试在 "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\" 中找到直接文件路径。它只是引发了另一个错误,即无法从 Windows.h 中包含另一个 header。我认为是 "excpt.h"

添加 DirectX header 时,您将 header 搜索路径更改为 DirectX 的搜索路径。那不应该是更改,您应该添加现有列表的路径。您有效地删除了 Windows.h

的路径

对于 Visual C++ 2015,您使用的是 Windows 8.1 SDK(默认情况下)或 Windows 10 SDK。在这两种情况下,您的路径中已经有 DirectXMath, D3DCompile 和其他 Direct3D headers 以及标准 Windows SDK 中的 FXC 着色器编译器。

如果您需要使用像 D3DX11 这样的遗留组件,您可以添加遗留的 DirectX SDK 路径,但您应该在 标准路径之后,而不是之前,在 VC++ 目录属性。

$(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include

$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x86

$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(DXSDK_DIR)Lib\x64

Where is the DirectX SDK? and Where is the DirectX SDK (2015 Edition)?

Of course, ideally you'd just avoid the legacy DirectX SDK all together. See Living without D3DX

UPDATE: Note if you need D3DX9, D3DX10, and/or D3DX11 only you can also get those headers/libs/DLLS directly from NuGet rather than dealing with the mess of installing/using the legacy DirectX SDK. See this blog post.