0

I'm trying to learn DirectX 11 and currently working on lighting. I need to add a Directional light to the scene, but when I set up my LightHelper.h file, it refuses to compile. It throws the error X1507 "failed to open source file: Windows.h".

I've tried uninstalling the Windows SDK and reconfiguring some of the include options to no avail. Here is my code for the header file.

    #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;
    };

This isn't the only header file (of course) with Windows.h, but all of the others link with no issues... I've been trying to figure it out for a couple days now. It's rather annoying.

Thanks

Edit: These are the solutions I tried.

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

I also tried finding the direct file path in "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\". It just threw another error about not being able to include another header from Windows.h. I think it was "excpt.h"

Community
  • 1
  • 1
abyssmu
  • 165
  • 1
  • 12
  • Try it without the capital W – user4581301 Nov 11 '16 at 03:52
  • It throws the same error. :( – abyssmu Nov 11 '16 at 03:53
  • 1
    What happens with a different project? A simple little hello world that includes windows.h just to see if it can? – user4581301 Nov 11 '16 at 03:57
  • Created a blank project and did as you suggested - a quick hello world - and no error popped up. – abyssmu Nov 11 '16 at 04:05
  • Sounds like the IDE is OK then. Something wrong in the project. Did you make the project from scratch or was it downloaded from the Internet and possibly expecting a different tools lay-out or Visual Studio version? – user4581301 Nov 11 '16 at 04:14
  • I did download it from my class (school not code class) files, but the file settings seem to be okay. I copied the code file-by-file into an empty project to see what might have been the problem. It turned out that LightHelper.fx was causing the problem. I don't know why... But the project compiles perfectly fine now that it has been removed. I even added it to a random .cpp file to check. Completely good. Now I just need to figure out how to get all the normals and stuff in order to add the light functionality... Ahh learning. Thanks for your help. :) – abyssmu Nov 11 '16 at 06:01
  • had the same problem, it turned out that I mistyped #include "LightHelper.h" in the .fx file, when it should've been #include "LightHelper.fx". After changing it, it compiled fine. – nairdaen Jan 20 '19 at 03:05

2 Answers2

1

With Visual C++ 2015, you are using either the Windows 8.1 SDK (by default) or the Windows 10 SDK. In both cases, you already have DirectXMath, D3DCompile, and other Direct3D headers in your path as well as the FXC shader compiler as those are in the standard Windows SDKs.

If you need to use legacy components like D3DX11, you can add the legacy DirectX SDK paths but you should do so after the standard paths, not before, in the VC++ Directories properties.

$(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

See 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.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
0

When you added the DirectX header, you changed the header search path to that of DirectX. That shouldn't have been a change, you should have added the path to the existing list. You effectively removed the path to Windows.h

MSalters
  • 173,980
  • 10
  • 155
  • 350