Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target Windows XP in Microsoft Visual Studio C++ [duplicate]

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:

#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?

like image 659
Tyler Tian Avatar asked Feb 27 '16 02:02

Tyler Tian


People also ask

Does Visual Studio support Windows XP?

Support for Windows XP development is available by using the Visual Studio 2017 v141_xp toolset. You can install the v141_xp toolset as an individual component option in the Visual Studio Installer.

Can Visual Studio 2019 run on Windows XP?

Visual Studio 2019 and later versions don't include current toolset support for creating code for Windows XP. Support for Windows XP development by using the v141_xp toolset that shipped in Visual Studio 2017 is still available as an optional component in the Visual Studio Installer.

Can VS code run on Windows XP?

From VS CodeSelect the extension tab. Search for @category:"themes" windows XP . Locate the theme and click Install.


2 Answers

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

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_xp toolset to use with the 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_xp Platform 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.

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.

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 post for details.

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:

Modify

like image 143
Chuck Walbourn Avatar answered Sep 22 '22 05:09

Chuck Walbourn


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

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

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

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


Update from Chuck Walbourn -

Note that in the particular case of VS 2015 Update 3 and VS 2017, you can use the VS 2017 or 2019 REDIST and it will work fine. See:

And to repeat - your "setup" should include a compatible MSVC runtime (aka "VCRedist").

like image 40
paulsm4 Avatar answered Sep 19 '22 05:09

paulsm4