如何在 Microsoft Visual Studio C++ 中以 Windows XP 为目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35664861/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:32:45  来源:igfitidea点击:

How to target Windows XP in Microsoft Visual Studio C++

c++windowsvisual-c++visual-studio-2015

提问by Tyler Tian

I'm using Microsoft Visual Studio 2015 on Windows 8.1. I want to compile a program targeting Windows XP. I've looked it up on Google and other similar questions, but none helped. In the solution settings, target platform toolset is set to the Windows XP one, but there is no option for Windows XP in the target platform version. I did read https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx(Using the Windows Headers) and added these lines to my program:

我在 Windows 8.1 上使用 Microsoft Visual Studio 2015。我想编译一个针对 Windows XP 的程序。我在谷歌和其他类似的问题上查过它,但没有任何帮助。在解决方案设置中,目标平台工具集设置为 Windows XP 之一,但目标平台版本中没有 Windows XP 选项。我确实阅读了https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745( v=vs.85) .aspx(使用 Windows 标头)并将这些行添加到我的程序中:

#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define NTDDI_VERSION NTDDI_WINXP

But it still doesn't work. It says that it can't find "MSVCP140.dll". After I got this dll, it begins to complain about can't find "VC140.dll". After that is "ucrtbased.dll", and then finally "api-ms-win-core-string-11-1-0.dll", which I don't even have it in my Windows 8.1 computer. The program can run on Windows 8.1, but not Windows XP. What can I do to make the program run on Windows XP?

但它仍然不起作用。它说它找不到“MSVCP140.dll”。拿到这个dll后,它开始抱怨找不到“VC140.dll”。之后是“ucrtbased.dll”,最后是“api-ms-win-core-string-11-1-0.dll”,我什至在我的 Windows 8.1 计算机中都没有。该程序可以在 Windows 8.1 上运行,但不能在 Windows XP 上运行。我该怎么做才能使程序在 Windows XP 上运行?

回答by Chuck Walbourn

In order to build a Windows XP compatible EXE with VS 2015 (or VS 2012 / VS 2013) you have to use the v140_xpPlatform Toolset rather than the default v140Platform Toolset.

为了使用 VS 2015(或 VS 2012 / VS 2013)构建与 Windows XP 兼容的 EXE,您必须使用v140_xp平台工具集而不是默认的v140平台工具集。

UPDATE:Note that VS 2017 includes support for Windows XP via v141_xp. For VS 2019, this feature is no longer being updated but you can still install the v141_xptoolset to use with the VS 2019 IDE.

更新:请注意,VS 2017 通过v141_xp. 对于 VS 2019,此功能不再更新,但您仍然可以安装v141_xp工具集以与 VS 2019 IDE 一起使用。

See your Project Properties, the General page:

查看您的项目属性,常规页面:

Property Page

属性页

This is because the default Platform Toolset uses the Windows 8.1 SDK (or you can opt into the Windows 10 SDK), and this only supports building applications for Windows Vista or later. When you select the v140_xpPlatform Toolset, you are using a version of the Windows 7.1 SDK which was the last version to support targeting Windows XP or Windows Server 2003.

这是因为默认平台工具集使用 Windows 8.1 SDK(或者您可以选择加入 Windows 10 SDK),并且这仅支持为 Windows Vista 或更高版本构建应用程序。当您选择v140_xp平台工具集时,您使用的是 Windows 7.1 SDK 的一个版本,它是支持面向 Windows XP 或 Windows Server 2003 的最后一个版本。

Note that Visual Studio can target Windows XP Service Pack 3 or Windows Server 2003 Service Pack 2. The C/C++ Runtime is not compatible with older versions of Windows.

请注意,Visual Studio 可以面向 Windows XP Service Pack 3 或 Windows Server 2003 Service Pack 2。C/C++ 运行时与旧版本的 Windows 不兼容。

If you are using DirectX in your app, this has some profound implications because a lot changed between the Windows 7.1 SDK and the Windows 8 SDK. See this postfor details.

如果您在应用中使用 DirectX,这会产生一些深远的影响,因为 Windows 7.1 SDK 和 Windows 8 SDK 之间发生了很大变化。有关详细信息,请参阅此帖子

With VS 2015, you will also need to select the Windows XP support in the Custom Install options or via Programs & Features / Microsoft Visual Studio 2015 / Change... / Modify:

对于 VS 2015,您还需要在自定义安装选项中或通过程序和功能/Microsoft Visual Studio 2015/更改.../修改选择 Windows XP 支持:

Modify

调整

回答by paulsm4

It sounds like the program runs fine on your development machine (Windows 8.1 + MSVS 2015), but doesn't run on an XP machine.

听起来该程序在您的开发机器(Windows 8.1 + MSVS 2015)上运行良好,但不能在 XP 机器上运行。

SOLUTION: you must include the MSVC runtime along with your .exe.

解决方案:您必须在 .exe 中包含 MSVC 运行时。

Look here: Deploying Native Desktop Applications (Visual C++)

看这里:部署本机桌面应用程序(Visual C++)

and here: Visual C++ Redistributable for Visual Studio 2015.

在这里:Visual C++ Redistributable for Visual Studio 2015