Visual Studio 2015: building with the Windows XP toolset selected still results in "not a valid win32 application" error on XP - c++

Visual Studio 2015 supports building C++ programs for Windows XP. According to the article Configuring C++11 Programs for Windows XP, enabling this support is simply a matter of selecting the appropriate platform toolset in the project properties.
This does not work in my case. A simple "hello world" program written in C++ and compiled in Visual Studio Community 2015 (version 14.0.24720.00 Update 1) with the platform toolset set to Visual Studio 2015 - Windows XP (v140_xp) and the platform set to x86/Win32 generates the generic "[name of executable] is not a valid Win32 application" error when run on a Windows XP computer.
Any suggestions would be appreciated. I've found a number of questions about similar issues (like these three), but nothing helpful yet.

Related

How can I set up Visual Studio 2017 to develop drivers?

According to this forum, https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware-winpc/windows-wdk-on-visual-studio-2017-community/fdbd2b44-e57a-4849-903d-04001205a764
Windows Driver Kit is not currently supported by visual studio 2017.
I tried installing the Windows Driver Kit, but the test driver projects, such as this one, fail to build
https://github.com/Microsoft/Windows-driver-samples/tree/master/serial/VirtualSerial
I get this error when building:
Error MSB8020 The build tools for WindowsUserModeDriver10.0 (Platform Toolset = 'WindowsUserModeDriver10.0') cannot be found. To build using the WindowsUserModeDriver10.0 build tools, please install WindowsUserModeDriver10.0 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
I already tried retargeting the Solution to the two options I have: 10.0.17134.0 and 8.1, but the same error keeps coming up.
What do I need to do to build this sample driver? Do I need to install VS2015? VS2017 community edition? Why isn't this WDK supported by the Visual Studio 2017 professional version?
Thanks,
Visual Studio 2017 definitely supports kernel-mode device driver development; there's no doubt about that because I've been using VS17 for it for many, many months.
Use the latest version of Windows Driver Kit (WDK) which can be downloaded and installed from MSDN: https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
Furthermore, you can always use the Enterprise WDK and then you can simply build using that if you wanted to from command-line. (Also can be found on page linked-to above)
Download the correct WDK installer for your edition of Visual Studio 2017:
WDK for Windows 10, version 1809 for Visual Studio Community 2017
WDK for Windows 10, version 1803 for Visual Studio Professional 2017
WDK for Windows 10, version 1709 for Visual Studio Enterprise 2017
Visit https://learn.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads for more information.
Not exactly a solution, but Windows 8.1 WDK works with Visual Studio 2017 Enterprise,
Download it from here, just need to retarget the project to 8.1
https://www.microsoft.com/en-us/download/confirmation.aspx?id=42273
In addition, I needed to get VS2015 C++ Build Tool to fix a missing Microsoft.cpp.props error
http://download.microsoft.com/download/5/F/7/5F7ACAEB-8363-451F-9425-68A90F98B238/visualcppbuildtools_full.exe
Developing drivers to windows is quite interesting one will be exposed to advanced Operating System Concepts.The set up for the environment will be IDE
IDE - Visual Studio (https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16)
Compilers (WDK)
Debugger (WDK)
WDK contains both(https://go.microsoft.com/fwlink/?linkid=2085767). Latest Visual Studio(VS2019) will come along with the latest WDK(10, 1903 as of now).
Sometimes plugins might not work properly i.e integration issues between Visual Studio and WDk.
By going to the location "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2019" and run VSIX installer.
Now in a new project, driver related templates are available.

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

This question already has answers here:
MSVCP140.dll missing
(4 answers)
Closed 6 years ago.
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?
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:
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:
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:
VC Runtime in MSVC 2017 is binary compatible with
2015
and
Microsoft Docs: C++ binary compatibility between Visual Studio
2015, 2017, and
2019.
And to repeat - your "setup" should include a compatible MSVC runtime (aka "VCRedist").

How to install Visual Studio Build Tools 2010 on Visual Studio 2015 Community?

I have a project created on Visual Studio 2010. When I try to run the project on Visual Studio 2015 Community edition I get the error below,
Severity Code Description Project File Line
Error MSB8020 The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". graphics C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets 55
And when I tried to build it with Visual Studio 2015 Build Tools I encountered about 1500+ errors.
Is there any way to make the project work?
If you can't install VS2010, Windows SDK for Windows 7 contains needed compiler tools (v100), you may actually skip installing the SDK itself and install only the compiler tools, headers and libs. Please note, that the compiler included in Windows SDK is the same that VS2010 has, but VS2010 SP1 has a bit newer compiler. If you need that, you'll also need to install Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1. But be aware, that if you install these, you may have issues later if you decide to install VS2010, there are bugs in installer that requires you to install components in strict order. Also, if your code uses MFC or ATL you must install VS2010, installing Windows SDK will not be enough.
You either install VS 2010 and build your project, or better yet you upgrade your projects. The VS 2015 custom install options will let you install the v120 Platform Toolset, but not the v110 or v100 Platform Toolsets.
One major change in VS 2015 is that the C++ tools (i.e. v140) are not installed by the Typical installation option. See the Visual C++ Team Blog.
Keep in mind that Visual C++ 2010 used the C++0x Draft Standard, and Visual C++ 2015 meets the C++11 Standard with the exception of Expression SFINAE (which is partly there in Update 1), so quite a bit has changed in the intervening years including some breaking changes. Since you are jumping three major releases at once--and about 10 minor updates--, it can be a bit overwhelming especially working through all the new warnings.
Another thing to keep in mind is that Visual C++ 2010 used the Windows 7.1 SDK, while Visual C++ 2012 or later use the Windows 8.x SDK. There's been a lot of change there too particularly for DirectX development. It's particularly important for Windows desktop apps that you set the _WIN32_WINNT preprocessor define for your target platform as the Windows 8.x SDK does not default to the 'oldest supported platform' like earlier Windows SDKs did. See Using the Windows Headers
VS 2010 and the v100 toolset supports targeting Windows XP and Windows Server 2003. The v140 toolset does not support targeting Windows XP / Server 2003. You have to use v140_xp Platform Toolset instead. See this post for some notes as this means you are again using the Windows 7.1 SDK rather than the Windows 8.x SDK with the _xp toolsets.
See Breaking Changes in Visual C++ 2012, Breaking Changes in Visual C++ 2013, and Breaking Changes in Visual C++ 2015.
See also Support For C++11/14/17 Features (Modern C++), and Where is the DirectX SDK?.
If you need to build the code both with VS 2010 and with VS 2015, then you should create two projects/solution files, one for each. You may also want to read this article for some notes on writing code that can build with multiple Visual C++ toolsets, which again is particularly challenging due to the Windows SDK changes.
VS 2015 supports targeting Windows Vista SP2, Windows 7 SP1, Windows 8.0, Windows 8.1, Windows 10, and optionally Windows XP SP3. It does not support targeting Windows Vista RTM, Windows Vista SP1, or Windows 7 RTM.

Visual Studio 2015 RC Community Edition Target Platform set to Windows 10 TP on Windows 8.1

I just freshly installed Windows 8.1 and Visual Studio 2015 RC Community Edition.
The compilation of an existing c++ project failed, not finding <windows.h> for include. In order to fix that I installed Windows 8.1 SDK with no luck.
Looking into it my Project Settings for the "Win32" configuration says:
Why does VS2015 display Windows 10 as default target platform and why can't I change the value to Windows 8.1?
The installation of
Microsoft Visual Studio 2015 Tools for Windows 10 (Technical Preview)
and
Windows Software Development Kit - Windows 10.0.10069
seems to be done by default during Visual Studio 2015 RC setup.
The optional selection of Windows 8.1 and Windows Phone 8.0/8.1 Tools does not seem to install the respective Platform Toolsets properly alongside of the Windows X versions in order to be able to change that on the respective project settings page.
Uninstalling the above mentioned Tool- and SDK-Kits for Windows 10 made
Target Platform Windows
available in the Project Settings and I can choose Version 8.1 now.
Now <windows.h> is found again.
I had the same problem.
I changed the platform toolset to v140_xp, and closed VS2015. After opening VS2015 asked to install Windows XP C++ libraries, 225MB. After these steps my project was compiled successfully. Hope this helps you.

Which XP version does Visual Studio 2012 supports [As Target OS]

Which version of windows XP does Visual Studio 2012 supports.
[Edit: Which version does VS12 supports compiling to]
I found this article:
http://blogs.msdn.com/b/vcblog/archive/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-2012.aspx
That states that it supports XP SP3. But I didn't find any information for VS12 update 4.
Also, If the code I compile using VS12 doesn't crush on XP SP2 and seems to work.
Is it safe to use it? why not?
Thanks
It's correct, Visual Studio 2012 can compile binaries compatible with Windows XP SP3.
You need to install the Platform Toolset v110_xp and select it in the general configuration properties of your project.
If "safe" means that it works the answere is yes. We have 12.000 installations of our software compiled with Visual Studio 2012 (and recently Visual Studio 2013) perfectly working on Windows XP SP3.
The only big problem is run time debugging: you can't install Visual Studio 2012 on Windows XP so it could be a problem to find bugs that accidentally happens only on Windows XP.