Не удается открыть Windows.h в Microsoft Visual Studio
Прежде всего: я использую Microsoft Visual Studio 2012
Я разработчик на C # / Java и сейчас пытаюсь программировать для kinect, используя Microsoft SDK и C ++. Итак, я начал с примера Основы цвета, и я не могу заставить его скомпилировать.
Сначала ни один из классов не смог найти Windows.h. Поэтому я установил (или переустановил, я не уверен) Windows SDK и добавил каталог включения SDK во включаемый «путь» проекта. Тогда все проблемы исчезли, кроме одной:
И это ошибка. Нет причин, по которым система может найти его, потому что он используется в нескольких других файлах, только этот файл не может с ним работать. В качестве ссылки, весь файл, который содержит ошибки (ColorBasics.rc):
Решение
Если вы этого еще не сделали, попробуйте добавить «SDK Path\Include» чтобы:
И добавить «SDK Path\Lib» чтобы:
Также попробуйте поменять «Windows.h» в
Если это не поможет, проверьте физическое существование файла, он должен находиться в папке «\ VC \ PlatformSDK \ Include» в каталоге установки Visual Studio.
Другие решения
Запустите Visual Studio. Перейдите в Инструменты-> Параметры и разверните Проекты и решения.
Выберите каталоги VC ++ из дерева и выберите «Включить файлы» в комбинированном списке справа.
Тебе следует увидеть:
Если этого не хватает, вы нашли проблему. Если нет, найдите файл. Он должен быть расположен в
C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Включить
C: \ Program Files (x86) \ Microsoft SDKs \ Windows \ v6.0A \ Включить
если VS был установлен в каталог по умолчанию.
Если вы ориентируетесь на Windows XP ( v140_xp ), попробуйте установить Поддержка Windows XP для C ++.
Начиная с Visual Studio 2012, набор инструментов по умолчанию (v110) прекратил поддержку Windows XP. В результате Windows.h ошибка может возникнуть, если ваш проект ориентирован на Windows XP с пакетами C ++ по умолчанию.
Проверьте, какая версия Windows SDK указана в вашем проекте Набор инструментов платформы. ( Project → Properties → Configuration Properties → General ). Если ваш Toolset заканчивается _xp Вам нужно будет установить поддержку XP.
Откройте установщик Visual Studio и нажмите изменять для вашей версии Visual Studio. Открой Отдельные компоненты вкладка и прокрутите вниз до Компиляторы, инструменты сборки и среды выполнения. Около дна, проверьте Поддержка Windows XP для C ++ и нажмите изменять начать установку.
Смотрите также:
Я получил эту ошибку фатальная ошибка lnk1104: не могу открыть файл ‘kernel32.lib’. эта ошибка возникает из-за отсутствия пути в каталогах VC ++. Для решения этой проблемы
Откройте Visual Studio 2008
- перейдите в каталог Tools-options-Projects and Solutions-VC ++- *
- затем в правом углу выберите Библиотека файлов
- здесь вам нужно добавить путь к kernel132.lib
В моем случае это C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Lib
Include windows h errors
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I have looked through the other posts concerning this error and I am sure that this situation is different.
I have a C++ COM ATL project and am trying to use CStringList which resides in
But when I include
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include
I’d be very grateful for any help. By the way the stdafx.h file looks like this:
#pragma once
#ifndef STRICT
#define STRICT
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off ATL’s hiding of some common and often safely ignored warning messages
#include causes a lot of syntax errors
My program uses Qt and OpenGL. It compiles correctly under Linux and Mac. When compiled on windows, I need to #include windows.h in order to use OpenGL, the code is like following,
However, there are a lot of error messages like
If I don’t #include windows.h, then those errors will not appear. I am using VS2013 with Qt 5.3.
2 Answers 2
OpenGL on Microsoft Windows is tied to WGL, which is in turn tied to GDI.
As a result, you cannot #include (you are indirectly doing this by including ) without first including some Windows-specific header that defines GDI/Windows pre-processor tokens such as WINGDIAPI and APIENTRY . But that is actually the extent to which any OpenGL program on Windows is tied to anything Windows-specific (header wise).
WinDef.h defines APIENTRY and WinGDI.h defines WINGDIAPI — including Windows.h brings in both of those headers (and a lot of other garbage unfortunately). So including Windows.h is mostly a convenience; to minimally compile OpenGL software on Windows you should #include followed by #include and then finally #include .
Alternatively, you can #define WIN32_LEAN_AND_MEAN just prior to #include and it will significantly reduce the number of unrelated things that are brought in by including that header. Many Visual C++ projects actually define that pre-processor definition by default when they are first created, you might want to see if your project is configured that way.