C++ 安装 Visual Studio 2010 后出现错误 C1189
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5839292/
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
error C1189 after installing Visual Studio 2010
提问by Krammig
I installed VS2010 after a drive crash, prior I had VS2005 and everything was fine.
我在驱动器崩溃后安装了 VS2010,之前我有 VS2005,一切都很好。
Now on compiling a C++ app that was fine previously I am seeing a couple of errors which I just cannot figure out.
现在在编译一个以前很好的 C++ 应用程序时,我看到了一些我无法弄清楚的错误。
Error 1 error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended. C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcore.h 35 1 BIOXGINA
错误 1 错误 C1189: #error : 此文件要求 _WIN32_WINNT 至少被 #defined 为 0x0403。建议使用 0x0501 或更高的值。C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcore.h 35 1 BIOXGINA
#ifndef __ATLCORE_H__
#define __ATLCORE_H__
#pragma once
#ifdef _ATL_ALL_WARNINGS
#pragma warning( push )
#endif
#pragma warning(disable: 4786) // identifier was truncated in the debug information
#pragma warning(disable: 4127) // constant expression
#include <atldef.h>
#include <windows.h>
#include <ole2.h>
#include <limits.h>
#include <tchar.h>
#include <mbstring.h>
#include <atlchecked.h>
#include <atlsimpcoll.h>
34. #if _WIN32_WINNT < 0x0403
35. #error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
36. #endif
#pragma pack(push,_ATL_PACKING)
namespace ATL
{
/////////////////////////////////////////////////////////////////////////////
// Verify that a null-terminated string points to valid memory
inline BOOL AtlIsValidString(
_In_z_count_(nMaxLength) LPCWSTR psz,
_In_ size_t nMaxLength = INT_MAX)
{
(nMaxLength);
return (psz != NULL);
}
If I comment out the above lines, I then get
如果我注释掉以上几行,我就会得到
error C3861 Identifier not found on line 111 below.
在下面的第 111 行中找不到错误 C3861 标识符。
I presume I'm only getting this because I commented the above lines ?
我想我得到这个只是因为我评论了上面的几行?
HRESULT Init() throw()
{
HRESULT hRes = S_OK;
111. if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0))
{
hRes = HRESULT_FROM_WIN32(GetLastError());
}
return hRes;
}
I would appreciate any assistance on this. Don't really want to reinstall 2005.
我将不胜感激。真的不想重新安装2005。
回答by p.campbell
This Microsoft Connect issuehas this potential solution:
此Microsoft Connect 问题具有以下潜在解决方案:
edit file "stdafx.h" and change the value defined for _WIN32_WINNT and WINVER to 0x0502.
编辑文件“stdafx.h”并将为 _WIN32_WINNT 和 WINVER 定义的值更改为 0x0502。
More discussion here about this error on the MSDN C++ forum: Problem with older VC Solution.
回答by Bo Persson
Your project targets a Windows version that is no longer supported by the newer compiler (or anything else).
您的项目面向较新的编译器(或其他任何东西)不再支持的 Windows 版本。
You have to select a minimum target version that is Windows XP ("Windows 5") or later.
您必须选择 Windows XP(“Windows 5”)或更高版本的最低目标版本。
回答by Krammig
Thank you both for the replies.
谢谢两位的回复。
I managed to get rid of the error message as follows. The Context.h looked liked this.
我设法摆脱了错误消息,如下所示。Context.h 看起来像这样。
#pragma once
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <winwlx.h>
#include <ObjBase.h>
#include <comdef.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <vector>
I moved the #define _WIN32_WINNT 0x0400 to then end after all the includes, and it compiled Ok. Odd, but it worked.
我将#define _WIN32_WINNT 0x0400 移动到所有包含之后结束,然后编译好了。奇怪,但它奏效了。
I will however alter it to 0x0502 as suggested.
但是,我会按照建议将其更改为 0x0502。
thanks
谢谢
回答by juan
Project Property –> Configuration Properties –> C/C++ -> Command Line ->Additional Options :add this code
Project Property -> Configuration Properties -> C/C++ -> Command Line ->Additional Options :添加这段代码
/D “_WIN32_WINNT=0×0501”
/D “_WIN32_WINNT=0×0501”
if in Windows server 2003,0×0501chagnes to 0×0502; if in Windows 7, 0×0501chagnes to 0×0601
如果在 Windows server 2003 中,0×0501 更改为 0×0502;如果在 Windows 7 中, 0×0501 更改为 0×0601
works well
效果很好