解决错误 This file requires _WIN32_WINNT to be #defined at least to 0x0403

解决错误 This file requires _WIN32_WINNT to be #defined at least to 0x0403…

看网上下载的代码,自己用vs2010打开,生成一个solution ,编译的时候出现错误:
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
双击错误定位到atlcore.h的一下语句:

#if _WIN32_WINNT < 0x0403
    #error This file requires _WIN32_WINNT to be #defined at least to 0x0403. 
           Value 0x0501 or higher is recommended.
#endif

因为搞不懂,上网查一查,有人说预编译加一句#define _WIN32_WINNT 0x0501,但是试了,还是不行。然后又查到一下方法。
首先看看工程中是否包含targetver.h这个头文件,如果没有的话,新建一个这个文件,文件内容如下:

#pragma once

// Including SDKDDKVer.h defines the highest available Windows platform.

// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>

接下来,
stdafx.h中包含这个文件#include "targetver.h" 编译一下没有错误。

至于为什么出现这个错误,以及问什么这么解决,暂时还不清楚。

猜你喜欢

转载自blog.csdn.net/u010921682/article/details/80195802