16

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?

Tyler Tian
  • 597
  • 1
  • 6
  • 22
  • Be more specific about the error. – Ben Voigt Feb 27 '16 at 02:10
  • Windows XP is no longer supported, and therefore versions of MS IDEs after it died no longer include support for that dead OS. If you want to target antiquated operating systems, use antiquated versions of the IDE. – Ken White Feb 27 '16 at 02:13
  • 1
    Dude - "Keeps on complaining about can't find a DLL file" is NOT HELPFUL. Please post *the exact error message*!!!! In general, most programs written for Win32 or MFC should run on just about any version of Windows... – paulsm4 Feb 27 '16 at 02:13
  • 2
    @KenWhite MS IDEs, up to and including VS2017, bundle toolchains named `vXXX_xp` to target XP. – ivan_pozdeev Dec 01 '17 at 18:21
  • Try and get a copy of visual cpp 2010. That works on xp and in CodeBlocks. On the record, I hate Visual Studio. It hogs memory, storage, is slow, terrible interface. Non intuitive; hard to use. It sucks. – user13947194 Aug 31 '21 at 12:43

2 Answers2

43

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

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • 2
    I did set it to v140_xp, but it still doesn't work. If it's not set to v140_xp, it gives the error message "xxxx.exe is not a valid win32 application". If I do set it to v140_xp, it complains about the missing DLLs I mentioned in the question. – Tyler Tian Feb 27 '16 at 14:12
  • 2
    Are you trying to run it on a Windows XP system or the machine you have VS 2015 installed on? – Chuck Walbourn Mar 01 '16 at 20:39
  • 1
    Have you installed the VC++ Redistributables on the target PC? Ex: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\1033\vcredist_x86.exe" – Pierre Mar 07 '17 at 22:02
  • 1
    I did just that, but with v141_xp (VS2017). "not a valid win32 application" UNLESS I specified /SUBSYSTEM:WINDOWS (Properties->Linker->System->SubSystem) – Freitags Jun 30 '17 at 18:59
  • 1
    I'm not sure how you have your project set up, but I was assuming you started from a correctly created Win32 desktop project. – Chuck Walbourn Jul 01 '17 at 04:51
  • "Note that Visual Studio can target Windows XP Service Pack 3 or Windows Server 2003 Service Pack 2." - how though? Both v140_xp and v141_xp target XP, not XP-SP2. e.g. the NTDDI_VERSION is still smaller than NTDDI_WINXPSP2, so CALG_SHA_256 is not enabled. – T.S Dec 11 '19 at 10:22
  • You still need to set ``_WIN32_WINNT`` to 0x0502. The key point is that the Visual C++ CRT doesn't support anything older than XP-SP3. – Chuck Walbourn Dec 11 '19 at 22:49
3

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").

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • 3
    Note: both links target the same page – JeffRSon Jul 27 '16 at 09:28
  • Both links are dead – T.S Jun 19 '19 at 08:29
  • 1
    @T.S - things change in three years :) Links updated. By now, toolsets have changed, too. I'm no longer sure what a developer needs to do to ensure their exe runs under Windows XP (EOL'ed April 8, 2014). This additional link might help: [Configuring Programs for Windows XP, 5/15.2019](https://learn.microsoft.com/en-us/cpp/build/configuring-programs-for-windows-xp?view=vs-2019) – paulsm4 Jun 19 '19 at 17:37
  • Legacy code. And no chance at a rewrite anytime soon. – T.S Dec 11 '19 at 10:25
  • 1
    @T.S - Six month delay responding to a 3 year old post about a release that was EOL'ed five years ago. Love it :) ANYWAY - the answer remains the same: find yourself a copy of VC++ Redistributable that's compatible with XP, ship it with your product, and install it in your "setup" :) – paulsm4 Dec 11 '19 at 21:05
  • 1
    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 [this blog post](https://devblogs.microsoft.com/cppblog/binary-compatibility-and-pain-free-upgrade-why-moving-to-visual-studio-2017-is-almost-too-easy/) and [Microsoft Docs](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017). – Chuck Walbourn Jul 27 '20 at 17:27