2011-04-30 234 views
18

我在安装VS2010之后发生了一次驱动器崩溃,之前我有过VS2005,一切都很好。错误C1189安装Visual Studio 2010之后

现在编译一个以前很好的C++应用程序,我看到了一些我无法弄清楚的错误。

错误1错误C1189:#error:此文件要求_WIN32_WINNT至少定义为0x0403。建议值0x0501或更高。 C:\ Program Files文件\微软的Visual Studio 10.0 \ VC \ atlmfc \ \包括35 atlcore.h 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); 
} 

如果我注释掉上面的行,我再拿到

错误下面第111行未找到C3861标识符。

我认为我只是得到这个,因为我评论了上面的几行?

HRESULT Init() throw() 
{ 
    HRESULT hRes = S_OK; 

111.  if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0)) 
    { 
     hRes = HRESULT_FROM_WIN32(GetLastError()); 
    } 

    return hRes; 
} 

我希望对此有任何帮助。真的不希望重新安装2005

回答

24

Microsoft Connect issue有这个可能的解决方案:

编辑文件“stdafx.h中”,并更改_WIN32_WINNT和WINVER定义为0x0502值。

更多关于此error on the MSDN C++ forum: Problem with older VC Solution的讨论。

+0

而不是更改系统文件stdafx。h,我选择在我的项目的预处理器定义中设置它们。比修补系统.h文件更便于携带。 – 2013-02-16 13:42:00

+1

@PeteMagsig:'stdafx.h'不是系统文件。它的代码被新建项目向导自动放置到项目中,成为预编译头文件的焦点,但它不会与其他任何文件共享。 (文件名是可怕的) – 2013-05-19 04:22:58

+0

@ BenVoigt:谢谢你指出。我没有意识到这是stdafx.h的来源。我仍然赞成在编译器配置中使用预处理器定义。 – 2013-05-19 12:44:17

5

您的项目的目标是新版编译器(或其他)不再支持的Windows版本。

您必须选择Windows XP(“Windows 5”)或更高版本的最低目标版本。

+0

编译器并不在意,它是一些老版本Windows的版本库。 C运行时库有一些重要的功能,它们依赖于WinXP的特性来处理非必要的任务,因此很难避免。但是这个特殊问题是ATL对XP中引入的函数的依赖。 – 2013-05-19 15:54:39

2

谢谢你们的回复。

我设法摆脱错误消息,如下所示。 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> 

我移动了#define _WIN32_WINNT 0x0400,然后在包含所有内容后结束,它编译成Ok。奇怪的,但它的工作。

然而,我会改变它为0x0502建议。

感谢

2

项目属性 - >配置属性 - > C/C++ - >命令行 - >附加选项 :添加此代码

/d“_WIN32_WINNT = 0×0501”

如果在Windows Server 2003,0×0501chagnes为0×0502; 如果在Windows 7中,0×0501chagnes为0×0601

作品以及

+0

0x0500也可以 – Kira 2013-09-09 14:45:46