如何使用Visual Studio 2019以Windows 7为目标? 我想使用VisualStudio 2019来享受最新的C++添加,但是瞄准Windows 7。 < >我使用VS 2019向导(在Windows 10上运行)创建了Windows C++应用程序。

如何使用Visual Studio 2019以Windows 7为目标? 我想使用VisualStudio 2019来享受最新的C++添加,但是瞄准Windows 7。 < >我使用VS 2019向导(在Windows 10上运行)创建了Windows C++应用程序。,c++,winapi,windows-7,C++,Winapi,Windows 7,向导将创建一个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 t

向导将创建一个
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>
为了测试这一点,我在程序的主函数中调用了Windows7不支持的API()

该程序构建良好(静态链接CRT),在Windows 10中运行良好

在Windows 7中执行相同程序时失败,显示以下错误消息:

现在,该程序应该没有编译,因为我指定了Windows7目标,而上面提到的API在Windows7上不可用

这是Windows SDK中的错误吗


是否可以使用VS 2019和Windows 10 SDK瞄准Windows 7,在代码中使用Windows 7不支持的API或结构时在生成过程中出错,以及如何瞄准?VS 2019的工具集和最新的Windows 10 SDK支持瞄准Windows 7 Service Pack 1

您已经在Windows 10 SDK中正确配置了Windows标头:

#include <winsdkver.h>
#define _WIN32_WINNT 0x0601
#include <sdkddkver.h>
#包括
#定义_WIN32_WINNT 0x0601
#包括
您仍然可以在此模式下调用Windows 7不支持的API,这就是为什么在运行时调用
pathchappend
生成、链接和失败的原因

您看到的问题也可能与目标计算机上不存在通用C/C++运行时有关。在目标测试机器上安装和/或版本


请参阅。

这是否回答了您的问题@dewaffled:稍后我会详细阅读您链接的问题,但如果是关于与CRT的静态链接,我已经做了。对我来说,代码根本不应该编译,因为我试图调用Windows 7上不支持的API。您尝试使用win7中根本不存在的API集(API-ms-win-core-path-l1-1-0)和API(PathcHappend),并且根据所选版本,pathcch.h中没有任何条件块。因此,编译代码正常,构建正常,但将仅在win8+中运行。Windows 8中引入了Pathchappend。它在(
pathch.h
)中声明的头文件似乎根本没有对SDK版本进行任何测试,这就是编译成功的原因。这是SDK中的错误吗?我想是的。我静态链接到CRT。我是否仍应在Windows 7上安装其他DLL?难道我不能只部署一个用VS 2019构建并静态链接到CRT的EXE吗?此外,当我试图(故意)调用Windows 7上不支持的API时,我预计会出现构建失败。问题与CRT无关-API-ms-win-core-path-l1-1-0(又名kernelbase)和Pathchappend非CRT
#include <winsdkver.h>
#define _WIN32_WINNT 0x0601
#include <sdkddkver.h>