如何解决如何使用Visual Studio 2019定位Windows 7?
我想使用Visual Studio 2019来享受最新的C ++新增功能,但目标是Windows 7。
我使用VS 2019向导(在Windows 10上运行)创建了Windows C ++应用程序。
#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>
我遵循了注释行中的指示,并在targetver.h
中(在#include <SDKDDKVer.h>
行之前)添加了以下行:
// Target Windows 7 SP1
#include <WinSDKVer.h>
#define _WIN32_WINNT 0x0601
为了进行测试,我在程序的主要功能中调用了Windows 7中不支持的API(PathCchAppend
)。
程序运行良好(我静态链接 CRT),并且在Windows 10中运行良好。
在Windows 7中执行时,同一程序失败,并显示以下错误消息:
现在,该程序应该完全未编译,因为我指定了Windows 7目标,并且上述API在Windows 7上不可用。
这是Windows SDK中的错误吗?
是否可以使用VS 2019和Windows 10 SDK定位Windows 7,在代码中使用Windows 7中不支持的API或结构时,在构建过程中出现错误,以及如何?
解决方法
VS 2019的工具集和针对Windows 7 Service Pack 1的最新Windows 10 SDK支持。
您已经在Windows 10 SDK中正确配置了Windows标头:
#include <winsdkver.h>
#define _WIN32_WINNT 0x0601
#include <sdkddkver.h>
在这种模式下,您仍然可以调用Windows 7不支持的API,这就是为什么调用PathCchAppend
会在运行时生成,链接和失败的原因。
您看到的问题也可能与目标计算机上没有Universal C / C ++ Runtime有关。在目标测试计算机上安装x86和/或x64 native版本。
请参见Microsoft Docs。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。