Cannot open Windows.h in Microsoft Visual Studio
Asked Answered
P

9

41

First of all: I'm using Microsoft Visual Studio 2012

I am a C#/Java developer and I am now trying to program for the kinect using Microsoft SDK and C++. So I started of with the Color Basics example, and I can not get it to compile. At first, none of the classes were able to find Windows.h. So I installed (Or re-installed, I'm not sure) the Windows SDK, and added the include dir of the SDK to the include "path" of the project. Then all the problems were gone, except for one:

Error   5   error RC1015: cannot open include file 'windows.h'. C:\temp\ColorBasics-D2D\ColorBasics.rc  17  1   ColorBasics-D2D

And thats the error. No reasons why, the system can find it because it is used in multiple other files, only this file is not able to work with it. As a reference, the entire file that is bugging (ColorBasics.rc):

//------------------------------------------------------------------------------
// <copyright file="ColorBasics-D3D.rc" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_APP                 ICON                    "app.ico"

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_APP DIALOGEX 0, 0, 512, 424
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT | WS_EX_APPWINDOW
CAPTION "Color Basics"
CLASS "ColorBasicsAppDlgWndClass"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "Screenshot",IDC_BUTTON_SCREENSHOT,238,391,50,14
    CONTROL         "",IDC_VIDEOVIEW,"Static",SS_BLACKFRAME,0,0,512,384
    LTEXT           "Press 'Screenshot' to save a screenshot to your 'My Pictures' directory.",IDC_STATUS,0,413,511,11,SS_SUNKEN,WS_EX_CLIENTEDGE
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_APP, DIALOG
    BEGIN
    END
END
#endif    // APSTUDIO_INVOKED


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
    "#include ""windows.h""\r\n"
    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED
Pokpoke answered 5/10, 2012 at 14:58 Comment(0)
A
32

If you already haven't done it, try adding "SDK Path\Include" to:

Project → Preferences → C/C++ → General → Additional Include Directories

And add "SDK Path\Lib" to:

Project → Preferences → Linker → General → Additional Library Directories

Also, try to change "Windows.h" to <windows.h>

If won't help, check the physical existence of the file, it should be in "\VC\PlatformSDK\Include" folder in your Visual Studio install directory.

Automat answered 5/10, 2012 at 15:28 Comment(6)
Some answers: I am using Ultimate Edition of Visual Studio, I tried all the things in your post (include and lib), and also changed "Windows.h" to <Windows.h>. Nothing worked. Also the folder PlatformSDK does not exist in -MVS2012-/VC/, but it did in the WindowsSDK/Include folderPokpoke
For clarity's sake: after the edit on nov 12 '14 the correct steps were added, and thus this is the correct answer.Pokpoke
@Automat I have added the Include and Lib file to the project, but windows.h doesn't exist in the "\VC\PlatformSDK\Include" folder.Entrap
Adding the path represented by the variable also worked for me $(WindowsSdkDir)\include and $(WindowsSdkDir)\libUtah
@PavelRogovoy can you elaborate on how to do this on a commandline only build machine? Is this a path variable or do I have to set this in some config file?Tergiversate
Project > Preferences does not exist in Visual Studio 2019, so this answer does not work anymore.Grussing
V
14

If you are targeting Windows XP (v140_xp), try installing Windows XP Support for C++.

Starting with Visual Studio 2012, the default toolset (v110) dropped support for Windows XP. As a result, a Windows.h error can occur if your project is targeting Windows XP with the default C++ packages.

Check which Windows SDK version is specified in your project's Platform Toolset. (Project → Properties → Configuration Properties → General). If your Toolset ends in _xp, you'll need to install XP support.

Visual Studio: Project toolset

Open the Visual Studio Installer and click Modify for your version of Visual Studio. Open the Individual Components tab and scroll down to Compilers, build tools, and runtimes. Near the bottom, check Windows XP support for C++ and click Modify to begin installing.

Visual Studio Installer: XP Support for C++

See Also:

Veinlet answered 27/8, 2018 at 20:39 Comment(0)
I
13

Start Visual Studio. Go to Tools->Options and expand Projects and solutions. Select VC++ Directories from the tree and choose Include Files from the combo on the right.

You should see:

$(WindowsSdkDir)\include

If this is missing, you found a problem. If not, search for a file. It should be located in

32 bit systems:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include

64 bit systems:

C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Include

if VS was installed in the default directory.

Source: http://forums.codeguru.com/showthread.php?465935-quot-windows-h-no-such-file-or-directory-quot-in-Visual-Studio-2008!-Help&p=1786039#post1786039

Iinde answered 15/1, 2014 at 6:41 Comment(5)
On Windows 10: C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um\Windows.hSlusher
On Windows 10 it is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\IncludeDolf
For Visual Studio 2013, in the VC+++, the Paths were semi-colon seperated. So I had to add a semi-colon and then the path: Ex. $(IncludePath);$(VCInstallDir)atlmfc\include;C:\Program Files\Microsoft SDKs\Windows\v7.1\IncludePhilous
in vs17 it says it has been deprecated. So I cannot edit it, but the issue remainsNisi
In Visual Studio 2017: "VC++ Directories editing in Tools > Options has been depreciated. VC++ Directories are now available as a user property sheet that is added by default to all projects." Clicking ? leads to an online help page: learn.microsoft.com/en-us/cpp/ide/…Veinlet
A
7

For my case, I had to right click the solution and click "Retarget Projects". In my case I retargetted to Windows SDK version 10.0.1777.0 and Platform Toolset v142. I also had to change "Windows.h"to<windows.h>

I am running Visual Studio 2019 version 16.25 on a windows 10 machine

Attorneyatlaw answered 18/9, 2019 at 15:39 Comment(0)
D
1

1) Go to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A for VS2013

2) Copy the folders Include and Lib (you should check where are your folders in folder windows such as v7.1, v8, v6, etc.)

3) Paste them into C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC

I solved my problems like:

error lnk1104: cannot open file 'kernel32.lib'.
error c1083: Cannot open Windows.h

Thanks.

Dreg answered 28/7, 2020 at 12:39 Comment(0)
M
0

The right combination of Windows SDK Version and Platform Toolset needs to be selected Depends of course what toolset you have currently installed

SDK Version and Platform Toolset

Marroquin answered 6/11, 2020 at 20:32 Comment(0)
M
0

I started a new job (fresh computer) and installed Visual Studio Community 2019 (we're waiting for an update to VS 2022 Professional). We use C# and C++ solutions. Using VS Installer, I initially selected ".Net desktop development", "Desktop development with C++", and "Data storage and processing". Under "Desktop development with C++" additional options need to be checked. I added "Windows 10 SDK (10.0.18362.0)" (the latest) and errors about not finding windows.h (among others) were resolved. You may need other options like "C++ MFC for latest v142 build tools (x86 & x64)" (the latest I see) to get everything for your C++ solution.

Memorialist answered 5/12, 2022 at 15:22 Comment(0)
A
-1

I got this error fatal error lnk1104: cannot open file 'kernel32.lib'. this error is getting because there is no path in VC++ directories. To solve this problem

Open Visual Studio 2008

  1. go to Tools-options-Projects and Solutions-VC++ directories-*
  2. then at right corner select Library files
  3. here you need to add path of kernel132.lib

In my case It is C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib

Archduchy answered 2/2, 2018 at 5:39 Comment(0)
O
-2

if anyone is facing this issue in Visual Studio, do the following steps:

  1. run the Visual Studio Installer
  2. go to modify
  3. untick the old version of Windows SDK version (for me, it was 10.0.18??????)
  4. tick the latest version of Windows SDK version (for me, it was 10.0.19??????)
  5. press OK and it will uninstall the old SDK and install the new SDK version with all the header files.
Overspend answered 1/11, 2021 at 11:54 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Solubilize

© 2022 - 2024 — McMap. All rights reserved.