Include windows h ошибка

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

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:tempColorBasics-D2DColorBasics.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"
END

2 TEXTINCLUDE 
BEGIN
    "#define APSTUDIO_HIDDEN_SYMBOLSrn"
    "#include ""windows.h""rn"
    "#undef APSTUDIO_HIDDEN_SYMBOLSrn"
    ""
END

3 TEXTINCLUDE 
BEGIN
    "rn"
    ""
END

#endif    // APSTUDIO_INVOKED

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



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


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

0 / 0 / 0

Регистрация: 05.05.2013

Сообщений: 189

1

16.12.2013, 13:13. Показов 4806. Ответов 5


При компиляции кода выводит ошибки. Сказали, что это может быть из за не подключения windows.h. Подскажите как исправить

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stdexcept>
#include <cstdlib>
 
class Fraction {
    long _numerator; //числитель
    long _denominator; // знаменатель
    // функция для проверки знаменателя на равенство нулю
    void check_zero() {
        if ( ! _denominator )
            throw std::runtime_error("Zero denominator!");
    }
 
public:
    // конструктор, принимающий значения числителя и знаменателя
    Fraction(long n, long d) : _numerator(n), _denominator(d) {
        check_zero();
    }
    // конструктор по умолчанию
    Fraction() : _numerator(1), _denominator(1) { }
    // конструктор копирования
    Fraction(const Fraction & f) { *this = f; }
    // деструктор
    ~Fraction() { }
    // перегруженный оператор =
    const Fraction & operator = (const Fraction & f) {
        if ( this != & f ) {
            _numerator = f.numerator();
            _denominator = f.denominator();
        }
        return *this;
    }
    // функции для доступа к числителю и знаменателю (константные - чтение, неконстантные - запись)
    long numerator() const { return _numerator; }
    void numerator (long n) { _numerator = n; }
    long denominator() const { return _denominator; }
    void denominator(long d) { _denominator = d; check_zero(); }
    // функция, возвращающая дробь в виде строки
    std::string str() const {
        if ( ! _numerator )
            return "0";
        std::ostringstream ost;
        ost << _numerator << '/' << _denominator;
        return ost.str();
    }
    // функция, возвращающая строку, содержащую "правильную дробь"
    // к примеру 5/2 будет выведено, как 2 1/2
    std::string correct_str() const {
        if ( _numerator >= _denominator ) {
            std::ostringstream ost;
            long whole = _numerator / _denominator;
            ost << whole;
            if ( _numerator % _denominator )
                ost << ' ' << ( _numerator - whole * _denominator ) << '/' << _denominator;
            return ost.str();
        }
        else
            return str();
    }
    // функция для сокращения дроби. 4/8 будет преобразованно в 1/2
    const Fraction & abbreviation() {
        for ( long i = _numerator; i > 1; --i ) {
            if ( _numerator % i == 0 && _denominator % i == 0 ){
                _numerator /= i;
                _denominator /= i;
                break;
            }
        }
        return *this;
    }
    // перегруженные функции для выполнения математических действий с дробями
    // см. учебник по математике примерно для пятого класса
    const Fraction operator * (const Fraction & f) const {
        Fraction n( _numerator * f._numerator, _denominator * f._denominator );
        n.abbreviation();
        return n;
    }
 
    const Fraction operator / (const Fraction & f) const {
        Fraction n( _numerator * f._denominator, _denominator * f._numerator );
        n.abbreviation();
        return n;
    }
 
    const Fraction operator + (const Fraction & f) const {
        Fraction n;
        if ( _denominator == f._denominator ){
            n.numerator(_numerator + f._numerator);
            n.denominator(_denominator);
        }
        else {
            n.numerator(_numerator * f._denominator + f._numerator * _denominator);
            n.denominator(_denominator * f._denominator);
        }
        n.abbreviation();
        return n;
    }
 
    const Fraction operator - (const Fraction & f) const {
        Fraction n;
        if ( _denominator == f._denominator ){
            n.numerator(_numerator - f._numerator);
            n.denominator(_denominator);
        }
        else {
            n.numerator(_numerator * f._denominator - f._numerator * _denominator);
            n.denominator(_denominator * f._denominator);
        }
        n.abbreviation();
        return n;
    }
};
 
// перегруженный оператор вывода в поток
std::ostream & operator << (std::ostream & ost, const Fraction & f) {
    ost << f.correct_str();
    return ost;
}
 
// функция для вывода русского текста
std::string tr(const char * text) {
    static char buf [ 2048 ];
    CharToOemA(text, buf);
    std::string s(buf);
    return s;
}
 
// вывод подсказки
void help() {
    std::cout << tr("Калькулятор дробей.") << "n"
        << tr("Введите запрос в виде 1/2 + 1/3 или 4 5/8 * 3 1/6") << "n"
        << tr("и нажмите enter.") << "n"
        << tr("Обратите внимание! Все данные вводятся через пробел,") << "n"
        << tr("между числителем, символом '/' и знаменателем") << "n"
        << tr("пробелы не допускаются!") << std::endl;
}
 
// вывод меню
int print_menu() {
    int m;
    std::cout << tr("n1 - вычислитьn2 - помощьn0 - выходn> ");
    std::cin >> m;
    std::cout << std::endl;
    std::cin.get();
    return m;
}
 
// разбор строки, вычисление, на выходе - строка с результатом
std::string calc(const std::string & arguments) {
    static const std::string operators("+-*/");
    long whole, numerator, denominator;
    char op;
    size_t pos;
    int op_pos;
    Fraction a, b;
    std::vector<std::string> avec;
    std::istringstream ist(arguments);
    std::string arg;
    while ( ist >> arg )
        avec.push_back(arg);
    if ( avec.size() < 3 || avec.size() > 5 )
        return tr("Ошибка ввода!");
    if ( operators.find(avec[1][0]) != std::string::npos ) {
        op_pos = 2;
        op = avec[1][0];
        whole = 0;
        if ( ( pos = avec[0].find('/') ) == std::string::npos ) {
            numerator = atol(avec[0].c_str());
            denominator = 1;
        }
        else if ( pos == 0 || pos == avec[0].size() - 1 )
            return tr("Ошибка ввода!");
        else {
            numerator = atol(avec[0].substr(0, pos).c_str());
            denominator = atol(avec[0].substr(pos + 1).c_str());
        }
    }
    else if ( operators.find(avec[2][0]) != std::string::npos ) {
        op_pos = 3;
        op = avec[2][0];
        whole = atol(avec[0].c_str());
        if ( ( pos = avec[1].find('/') ) == std::string::npos || pos == 0 || pos == avec[1].size() - 1 )
            return tr("Ошибка ввода!");
        numerator = atol(avec[1].substr(0, pos).c_str());
        denominator = atol(avec[1].substr(pos + 1).c_str());
    }
    else
        return tr("Ошибка ввода!");
 
    a.numerator(whole * denominator + numerator);
    a.denominator(denominator);
 
    if ( avec.size() - op_pos == 1) {
        whole = 0;
        if ( ( pos = avec[op_pos].find('/') ) == std::string::npos ) {
            numerator = atol(avec[op_pos].c_str());
            denominator = 1;
        }
        else if ( pos == 0 || pos == avec[op_pos].size() - 1 )
            return tr("Ошибка ввода!");
        else {
            numerator = atol(avec[op_pos].substr(0, pos).c_str());
            denominator = atol(avec[op_pos].substr(pos + 1).c_str());
        }
    }
    else {
        whole = atol(avec[op_pos].c_str());
        if ( ( pos = avec[op_pos + 1].find('/') ) == std::string::npos || pos == 0 || pos == avec[op_pos + 1].size() - 1 )
            return tr("Ошибка ввода!");
        numerator = atol(avec[op_pos + 1].substr(0, pos).c_str());
        denominator = atol(avec[op_pos + 1].substr(pos + 1).c_str());
    }
 
    b.numerator(whole * denominator + numerator);
    b.denominator(denominator);
 
    switch ( op ) {
    case '+' :
        return (a + b).correct_str();
    case '-' :
        return (a - b).correct_str();
    case '*' :
        return (a * b).correct_str();
    case '/' :
        return (a / b).correct_str();
    default :
        return tr("Ошибка ввода!");
    }
}
 
int main() {
    std::string buf;
    int mnu;
 
    while ( mnu = print_menu() ){
        switch ( mnu ) {
        case 1 :
            std::cout << tr("Запрос: ");
            std::getline(std::cin, buf);
            if ( buf.empty() )
                std::cerr << tr("Ошибка ввода!") << std::endl;
            else
                std::cout << tr("Результат: ") << calc(buf) << std::endl;
            break;
        case 2 :
            help();
            break;
        default:
            std::cerr << tr("Неверный выбор") << std::endl;
            break;
        }
    }
 
    return 0;
}

Ошибки: первая: «error LNK2028: ссылка на неразрешенную лексему (0A00040C) «extern «C» int __stdcall CharToOemA(char const *,char *)» (?CharToOemA@@$$J18YGHPBDPAD@Z) в функции «class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tr(char const *)» (?tr@@$$FYA?AV?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@PBD@Z)»
вторая: «error LNK2019: ссылка на неразрешенный внешний символ «extern «C» int __stdcall CharToOemA(char const *,char *)» (?CharToOemA@@$$J18YGHPBDPAD@Z) в функции «class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tr(char const *)» (?tr@@$$FYA?AV?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@PBD@Z)»

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



@gyurmey

Hi there. i have issue with using some C/C++ extension in vscode. it gives error as above.
My MacOS catalina version is 10.15.2 and VsCode version is Version: 1.38.1. i have similar error with other header extension such as conio.h and MMsystem.h etc. i have install mingw-w64 and also did the installation of vcpkg as suggested by vscode but still the error still there — . any suggestion would be great. thank you in advance «^^»

@Colengms

Hi @gyurmey . Do I understand correctly that you are running on MacOS, but have installed MinGW in order to target Windows? If so, I believe you would also need to install/extract a Windows 10 SDK to acquire the header files you are referring to.

@gyurmey

Hi @gyurmey . Do I understand correctly that you are running on MacOS, but have installed MinGW in order to target Windows? If so, I believe you would also need to install/extract a Windows 10 SDK to acquire the header files you are referring to.

thank you @Colengms for the answer. i have been trying to extract window 10 SDK or find a way to use it in MacOS but haven’t found any solution or executable files for MacOS. is there any other way or vscode extension that enable the headers? thank you ^^

@Colengms

Hi @gyurmey . How did you install MinGW? It looks like MinGW packages should include Windows headers. On Ubuntu Linux, windows.h is in the following packages:

mingw-w64-common
mingw-w64-i686-dev
mingw-w64-x86-64-dev

If you already have Windows headers installed, the issue you are seeing might be related to file system and case sensitivity. On Windows, the file system is (generally) not case sensitive, so a #include of «Windows.h» would find «windows.h». If the file system on your Mac is case sensitive, you may need to alter some casing used in source code to match the file system.

@gyurmey

Hi @gyurmey . How did you install MinGW? It looks like MinGW packages should include Windows headers. On Ubuntu Linux, windows.h is in the following packages:

mingw-w64-common
mingw-w64-i686-dev
mingw-w64-x86-64-dev

If you already have Windows headers installed, the issue you are seeing might be related to file system and case sensitivity. On Windows, the file system is (generally) not case sensitive, so a #include of «Windows.h» would find «windows.h». If the file system on your Mac is case sensitive, you may need to alter some casing used in source code to match the file system.

thank you again for the answer @Colengms .. i used the command brew install mingw-w64 . i tried to find the path for mingw but couldn’t find it. I tried to reinstall but it give warning that it is already installed.

@Colengms

Hi @gyurmey . I tried using brew install mingw-w64. It prompted me to run xcode-select --install and to also install gcc. That resulted in windows.h being found here: /usr/local/Cellar/mingw-w64/9.0.0_2/toolchain-x86_64/x86_64-w64-mingw32/nclude/windows.h

I then configured the C/C++ Extension to use x86_64-w64-mingw32-gcc by setting compilerPath to its path, in c_cpp_properties.json. Then I was able to #include windows.h in a source file, without getting any squiggles.

I did the above using Big Sur, but I suspect the process is the same or similar for Catalina.

Is the above enough information to help you solve the issue?

@gyurmey

Hi @gyurmey . I tried using brew install mingw-w64. It prompted me to run xcode-select --install and to also install gcc. That resulted in windows.h being found here: /usr/local/Cellar/mingw-w64/9.0.0_2/toolchain-x86_64/x86_64-w64-mingw32/nclude/windows.h

I then configured the C/C++ Extension to use x86_64-w64-mingw32-gcc by setting compilerPath to its path, in c_cpp_properties.json. Then I was able to #include windows.h in a source file, without getting any squiggles.

I did the above using Big Sur, but I suspect the process is the same or similar for Catalina.

Is the above enough information to help you solve the issue?
Thank you so much @Colengms . Now the squiggles are gone and i can go to the definition of the header file as is was not the case earlier. i also found a new compiler path in C/C++ config. but when i run the C/C++ file on vscode, it still give same error on the terminal even the file doesn’t have any error warning. ^^ .. i will try to dig deeper into it.. «^_^»

@Colengms

but when i run the C/C++ file on vscode, it still give same error on the terminal

Could you clarify what you mean by «run the C/C++ file»? Are you referring to running a particular command line in the terminal, using Build and Debug Active File, pressing F5 (Debug: Start Debugging), clicking on Run and Debug, or something else? :)

Config values in c_cpp_properties.json are used to configure IntelliSense (squiggles, colorization, etc.), and not used directly to compile sources. The C/C++ extension is separate from (though somewhat connectable to) the various build systems projects might employ (such as Make or CMake) to compile sources.

If you had previously used one of the various features to Build/Run/Debug a single source file, tasks.json and/or launch.json files were likely created the first time and persistent, and may need corrections. However, since you are running on macOS, and MinGW generates executables for Windows, I assume you would be unable to run the program directly from VS Code.

@gyurmey

but when i run the C/C++ file on vscode, it still give same error on the terminal

Could you clarify what you mean by «run the C/C++ file»? Are you referring to running a particular command line in the terminal, using Build and Debug Active File, pressing F5 (Debug: Start Debugging), clicking on Run and Debug, or something else? :)

Config values in c_cpp_properties.json are used to configure IntelliSense (squiggles, colorization, etc.), and not used directly to compile sources. The C/C++ extension is separate from (though somewhat connectable to) the various build systems projects might employ (such as Make or CMake) to compile sources.

If you had previously used one of the various features to Build/Run/Debug a single source file, tasks.json and/or launch.json files were likely created the first time and persistent, and may need corrections. However, since you are running on macOS, and MinGW generates executables for Windows, I assume you would be unable to run the program directly from VS Code.
Thank you @Colengms for the answer. i have tried running both from Build and Debug Active File command and also vscode run tab. i do have task.json and launch.json. i think windows.h is not supported in MacOS using vscode. i tried in Linux Ubuntu as well and i did the same procedure but result in same error. May be it is only supported in window itself but unfortunately, could not test it ^^ .

@Colengms

Hi @gyurmey . MinGW stands for «Minimalist GNU for Windows». You should be able to (cross-)compile with MinGW, but you will not be able to run the program you generate on macOS or Linux. The program it generates would only run on a Windows PC. If you would like to build an application for macOS or Linux, I’d suggest using the inbuild versions of clang or gcc on those platforms.

@gyurmey

Hi @gyurmey . MinGW stands for «Minimalist GNU for Windows». You should be able to (cross-)compile with MinGW, but you will not be able to run the program you generate on macOS or Linux. The program it generates would only run on a Windows PC. If you would like to build an application for macOS or Linux, I’d suggest using the inbuild versions of clang or gcc on those platforms.
thank you so much for thorough discussion and explanation.. @Colengms

See more:

Hi,
In my project after including some header files,it is showing the below error.When I removed those statements it is showing a bulk error of ‘178’ numbers.And I checked which are those including files.Can anyone help me how can I remove that error.

#ifdef _WINDOWS_
#error WINDOWS.H already included.  MFC apps must not #include <windows.h>
#endif

Thanks,


This may help someone. I got the same error from a UnitTest project.
I changed my stdafx.h to this:

#include "targetver.h"

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components

// Headers for CppUnitTest
#include "CppUnitTest.h"

// TODO: reference additional headers your program requires here

… and the error went.

Here are some of the rules I use for #include files which might be helpful to you:
— Use precompiled headers («#include <stdafx.h>»). This must be the first include in your .cpp file. It should never be in a .h file. [I also routinely rename the file to something project specific (eg. util_stdafx.h) in a multi-project environment so that the wrong file is not included somewhere. You can choose whether or not to do this…]
— Immediately after the stdafx.h file include should be the #include corresponding to your .cpp file. This way, the .h file will #include anything it needs to work properly.
— After these 2 includes in your .cpp file, include anything else needed for the .cpp file to run correctly.
— Header files that come with the compiler are called «Stable headers». These should be the only ones that appear in stdafx.h, along with #defines used by these headers (eg. WIN32_LEAN_AND_MEAN, _WIN32_WINNT etc.). If you are on windows, then stdafx.h is the only place you should see «#include <windows.h>»
— The first non-blank non-comment lines in header files should be either «#pragma once» or guard block definition (or both).

Check probably `Windows.h` might be included in your `stdafx.h` file. If so, then comment `Windows.h` and then check, the error may go off. Because I had the same problem I resolve in same way.

thanks from all of you
your solutions were good and applicational.

i solved it through the following method:

just add below precompile definitions :

#ifdef __windows__
#undef __windows__
#endif

and thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

Понравилась статья? Поделить с друзьями:
  • Include the error number and your oc serum
  • Include stdafx h ошибка как исправить
  • Include python h error
  • Include pyconfig h 59 fatal error c1083
  • Include pch h ошибка