C++ 无法在 Microsoft Visual Studio 中打开 Windows.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12748896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open Windows.h in Microsoft Visual Studio
提问by Cheiron
First of all: I'm using Microsoft Visual Studio 2012
首先:我使用的是 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:
我是一名 C#/Java 开发人员,我现在正在尝试使用 Microsoft SDK 和 C++ 为 kinect 编程。所以我从 Color Basics 示例开始,但我无法编译它。起初,没有一个类能够找到 Windows.h。所以我安装(或重新安装,我不确定)Windows SDK,并将SDK的包含目录添加到项目的包含“路径”中。然后所有的问题都消失了,除了一个:
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):
这就是错误。没有原因,系统可以找到它,因为它在多个其他文件中使用,只有这个文件无法使用它。作为参考,整个文件被窃听(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.hProject → Preferences → C/C++ → General → Additional Include Directories
"
END
2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"Project → Preferences → Linker → General → Additional Library Directories
"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"##代码##"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
采纳答案by Choufler
If you already haven't done it, try adding "SDK Path\Include"
to:
如果您还没有这样做,请尝试添加"SDK Path\Include"
到:
And add "SDK Path\Lib"
to:
并添加"SDK Path\Lib"
到:
Also, try to change "Windows.h"
to <windows.h>
另外,尝试更改"Windows.h"
为<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.
如果没有帮助,请检查文件的物理存在,它应该位于 Visual Studio 安装目录中的“\VC\PlatformSDK\Include”文件夹中。
回答by Andreyk6
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.
启动 Visual Studio。转到工具-> 选项并展开项目和解决方案。从树中选择 VC++ 目录,然后从右侧的组合中选择包含文件。
You should see:
你应该看到:
$(WindowsSdkDir)\include
$(WindowsSdkDir)\包括
If this is missing, you found a problem. If not, search for a file. It should be located in
如果缺少此项,则说明您发现了问题。如果没有,请搜索文件。它应该位于
32 bit systems:
32位系统:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include
64 bit systems:
64位系统:
C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Include
C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Include
if VS was installed in the default directory.
如果 VS 安装在默认目录中。
来源:http: //forums.codeguru.com/showthread.php?465935-quot-windows-h-no-such-file-or-directory-quot-in-Visual-Studio-2008!-Help&p=1786039#post1786039
回答by Stevoisiak
If you are targeting Windows XP (v140_xp
), try installing Windows XP Support for C++.
如果您的目标是 Windows XP ( v140_xp
),请尝试安装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.
从 Visual Studio 2012 开始,默认工具集 (v110) 不再支持 Windows XP。因此,Windows.h
如果您的项目面向具有默认 C++ 包的 Windows XP,则可能会发生错误。
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.
检查在您的项目的Platform Toolset 中指定了哪个 Windows SDK 版本。( Project → Properties → Configuration Properties → General
). 如果您的工具集以 结尾_xp
,则您需要安装 XP 支持。
Open the Visual Studio Installer and click Modifyfor your version of Visual Studio. Open the Individual Componentstab and scroll down to Compilers, build tools, and runtimes. Near the bottom, check Windows XP support for C++and click Modifyto begin installing.
打开 Visual Studio 安装程序,然后针对您的 Visual Studio 版本单击修改。打开Individual Components选项卡并向下滚动到Compilers, build tools, and runtimes。在底部附近,检查Windows XP 对 C++ 的支持,然后单击修改开始安装。
See Also:
也可以看看:
回答by Goku
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>
就我而言,我必须右键单击解决方案,然后单击“重新定位项目”。就我而言,我重新定位到 Windows SDK 版本 10.0.1777.0 和平台工具集 v142。我也不得不"Windows.h"
改为<windows.h>
I am running Visual Studio 2019 version 16.25 on a windows 10 machine
我在 Windows 10 机器上运行 Visual Studio 2019 版本 16.25
回答by Varun Challa
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
我收到此错误致命错误 lnk1104:无法打开文件 'kernel32.lib'。出现此错误是因为 VC++ 目录中没有路径。为了解决这个问题
Open Visual Studio 2008
打开 Visual Studio 2008
- go to Tools-options-Projects and Solutions-VC++ directories-*
- then at right corner select Library files
- here you need to add path of kernel132.lib
- 转到工具-选项-项目和解决方案-VC++ 目录-*
- 然后在右上角选择库文件
- 这里需要添加kernel132.lib的路径
In my case It is C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
在我的情况下它是 C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib