I compile my C++ source code with Visual Studio 11 Developer Preview. I statically link to the runtime library.
The resulting executable cannot be executed on Windows XP. When I try to execute it on Windows XP I get the error message "[Executable Path] is not a valid Win32 Application.".
According to Microsoft Visual Studio 11 won't support Windows XP.
How does it work that the resulting executable cannot be executed on Windows XP? Is there anything special within the executable?
They seem to drop support for older systems in every new release of VS (NT4,2000,XP) Even if you don't use the CRT at all, they still force the PE subsystem version to high numbers. You can work around that by changing the numbers back to 5.0 in a post build step. Just changing those numbers should allow the exe to start on XP unless the new CRT is using WinAPI functions that don't exist on XP.
The other alternative if you want to keep using VS11 is to use multi-targeting and older compilers...
Visual Studio 2012 will be able to target Windows XP later in 2012:
Targeting Windows XP with C++ in Visual Studio 2012
"Later this fall, Microsoft will provide an update to Visual Studio 2012 that will enable C++ applications to target Windows XP. This update will make the necessary modifications to the Visual C++ 2012 compiler, runtime, and libraries to enable developers to create applications and DLLs that run on Windows XP and higher versions as well as Windows Server 2003 and higher."
Edit: This has now happened (phew!)
The workaround is to use a different Platform Toolset, which will link a different version of CRT and produce binaries compatible to older operating systems.
See more here: Target Windows XP in Visual Studio 11 Beta using the Visual Studio 2010 compiler and libraries.
With v90 toolset your binary will be able to run even in older systems, such as Windows 2000.
http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7444.BlogPic.png
The runtime libraries bundled with VS 2010 and higher enforce your executable to import two new functions from kernel32.dll that are missing on Windows XP: EncodePointer and DecodePointer. Those are needed for yet another idiotic naive attempt to enhance the software "security".
In VS 2010 there is an option to use the runtime libraries of Visual Studio 2008, which solves this problem. I don't know if there's such an option in later versions of VS.
Related
As I read this article, it is enough to download most recent MSVS 2022 and then install toolset C++ Windows XP Support for VS 2017 (v141) tools [Deprecated].
After that in Visual Studio inside project properties I set this toolset. According to linked article it is enough to compile C++ app with XP support.
But after my .exe file is created if I run it on XP 64-bit SP2 then it shows error that CompareStringEx function is not found in KERNEL32.DLL.
Hence it appears that it is not enough to use this toolset. Something else is needed.
In some other places I see that one needs also to add define /D_USING_V110_SDK71_ when compiling and option /SUBSYSTEM:CONSOLE,5.01 when linking. In my project properties I also tried to add this two options, but still CompareStringEx is inside import table of final application.
As suggested by #BenVoigt, I did defines /DWINVER=0x0502 /D_WIN32_WINNT=0x0502. Also set C++ standard to /std:c++14 (I would set C++11 but this MSVS version allows to set only C++14 at minimum). Still some non-XP symbols remain in final EXE like InitializeSRWLock that is possibly used by C++11's std::mutex in my code.
Does anyone know everything what is needed in order to compile fully XP-compatible application?
Update. I managed to build working XP application by doing things above plus setting C++ CRT runtime to Multi Threaded DLL, i.e. using dynamic DLL linkage of CRT. Also as suggested by #ChuckWalbourn (down x86 or x64 redists), I downloaded older version of msvcp140.dll.
But it is very important for my project to have statically linked runtime (C++ CRT), i.e. use Multi Threaded value for Runtime field in project properties. Only if it is REALLY not possible only then I will use DLL CRT. Until then solution about how to link CRT statically are welcome, of course to produce XP-compatible EXE.
TL;DR For Window XP VC++ REDIST support, install https://aka.ms/vs/15/release/VC_redist.x86.exe on your Windows XP system
-or-
if you are doing "side-by-side application local deployment", then use the DLLs from C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Redist\MSVC\14.16.27012\x86\Microsoft.VC141.CRT.
If you want the latest bug fixes to the CRT, you can also download the REDIST for VS 2019 (16.7) per the link on Microsoft Docs.
For Windows XP targeting, you use the v141_xp Platform Toolset installed by Visual Studio (VS 2017, VS 2019, or VS 2022) which is the latest VS 2017 (v141) C++ compiler using an included Windows 7.1A SDK.
Make sure you have installed (for VS 2022) the following individual components since you are using MFC:
Microsoft.VisualStudio.Component.WinXP: C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]
Microsoft.VisualStudio.Component.VC.v141.x86.x64: MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
Microsoft.VisualStudio.Component.VC.v141.MFC: C++ MFC for v141 build tools (x86 & x64)
If you are doing DirectX development, be sure to read this blog post as well for various implications of using the Windows 7.1A SDK.
For deployment to Windows XP, you can install the latest VS 2017 Visual C++ REDIST or use VS 2019 Visual C++ up to VS 2019 (16.7). After that the REDIST DLLs themselves are not compatible with Windows XP.
On your development system with VS 2022 installed, you are going to have a newer set of Visual C++ REDIST files which are binary compatible with your v141_xp Platform Toolset built EXE, but those VC++ REDIST DLLs are not compatible with Windows XP.
IOW: If you look at a dumpbin /imports of the 14.30 (v143 version), 14.29 (v142 latest version), and/or 14.16 (v141 latest version ) copies of msvcp140.dll you will see different imports. The msvcp140.dll sitting in your C:\windows\SysWOW64 folder is going to be the 14.30 version.
Our Windows application (developed in Delphi) is shipped in 32-bit and 64-bit editions. Users can write plugins for it. If they target the 32-bit edition, the need to create a 32-bit dll. If they target the 64-bit edition, they need to target a 64-bit dll.
I would like to create a sample application in Visual Studio C++ that can be used as a reference to help hacking it.
I would like that the Visual Studio solution provided as an example is able to have everything in place to compile a sample dll both for Win32 and for Win64.
Which is the minimum (preferably free) Visual Studio C++ edition or version that I need to be able to compile both for Win32 and Win64. I tried with Visual Studio 2010 Express but it does not seem to let you add Win64 as a target platform.
VS2012 Express includes the 64 bit compiler. It is possible to persuade earlier versions of the Express edition to use the 64 bit tools, but it's quite tricky to set up.
I develop a large open source C++ program. On Windows, we typically build our downloadable releases with Visual Studio Express. In the past, I've tried to use an old version of Windows and an old version of Visual Studio to try to maintain compatibility with as many user's machines as possible -- and to also keep the development environment as accessible as possible to contributors.
We do use some C++11. We currently use VS 2010 Express on Windows 7 Enterprise SP1 (64 bit). We target Win32. We do not use any .Net stuff.
Unfortunately, as built, our program crashes on Windows 8.1 -- it starts to load, but crashes with a non helpful error message 'myprogram.exe Has stopped working.' I can't yet tell if this 'should work', or if it is a bug in our program that only Win8 triggers (it works fine on earlier Windows as well as OSX and Linux).
I'm finding it very difficult to figure out the target compatibility matrix for Windows & Visual Studio. Assume that all versions of Windows and Visual Studio are available.
So, what version of Visual Studio and/or Windows SDK 'should work' to produce a single executable that will work on the widest range of Windows versions?
Or, what is the minimum number of builds (and how) we could do to target the widest array of Windows versions?
Alternatively, would MinGW provide a substantially better result for us? If so, which version & platform should we use?
We currently only build 32-bit versions, but how would going 64-bit change this discussion?
I have compilled program in Visual Studio 2011 on Windows consumer preview with v110 toolkit (c runtime 2011) and it refuse to run on Windows XP even with needed runtime dlls for 2011 libs (from VC/redist/) folder. It says that file is not valid Win32 app. How I can get that app to run on XP?
The VS 11 Beta does not support Windows XP as a target platform (or as a development platform, just to be complete).
There have been some statements from Microsoft personnel that this might change for RTM.
But I wouldn't hold my breath.
If you're adventurous, here's an article that describes in detail how you can create your own library that will smooth over the things that prevent the runtime library from allowing an application to load on WinXP:
How to get Visual C++ 2012 (VC 11 Beta) statically linked CRT and MFC applications to run on Windows XP
Update (15 June 2012):
Microsoft has reconsidered not allowing VC++ 2012 to target Window XP. Unfortunately the decision came too late to allow targeting WinXP to be supported in RTM, so you'll have to wait for a subsequent update:
Targeting Windows XP with C++ in Visual Studio 2012
Applications compiled with Visual Studio 11 do not run on XP. Please vote for this request -- perhaps Microsoft will realize their mistake then.
Use a 32-bit cross-compiler, or rebuild the app on Windows XP for 32-bit.
Unfortunately there are changes to the PE version as well as the CRT for Visual Studio 2011 which means, even with binary modification (yuk) XP is not supported. To quote the answer from Microsoft:
Visual Studio 11 Beta doesn't support Windows XP. As to Visual Studio
11 final release, there's no such information published yet. We will
refer to the official website for supported OS.
I compile my C++ source code with Visual Studio 11 Developer Preview. I statically link to the runtime library.
The resulting executable cannot be executed on Windows XP. When I try to execute it on Windows XP I get the error message "[Executable Path] is not a valid Win32 Application.".
According to Microsoft Visual Studio 11 won't support Windows XP.
How does it work that the resulting executable cannot be executed on Windows XP? Is there anything special within the executable?
They seem to drop support for older systems in every new release of VS (NT4,2000,XP) Even if you don't use the CRT at all, they still force the PE subsystem version to high numbers. You can work around that by changing the numbers back to 5.0 in a post build step. Just changing those numbers should allow the exe to start on XP unless the new CRT is using WinAPI functions that don't exist on XP.
The other alternative if you want to keep using VS11 is to use multi-targeting and older compilers...
Visual Studio 2012 will be able to target Windows XP later in 2012:
Targeting Windows XP with C++ in Visual Studio 2012
"Later this fall, Microsoft will provide an update to Visual Studio 2012 that will enable C++ applications to target Windows XP. This update will make the necessary modifications to the Visual C++ 2012 compiler, runtime, and libraries to enable developers to create applications and DLLs that run on Windows XP and higher versions as well as Windows Server 2003 and higher."
Edit: This has now happened (phew!)
The workaround is to use a different Platform Toolset, which will link a different version of CRT and produce binaries compatible to older operating systems.
See more here: Target Windows XP in Visual Studio 11 Beta using the Visual Studio 2010 compiler and libraries.
With v90 toolset your binary will be able to run even in older systems, such as Windows 2000.
http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7444.BlogPic.png
The runtime libraries bundled with VS 2010 and higher enforce your executable to import two new functions from kernel32.dll that are missing on Windows XP: EncodePointer and DecodePointer. Those are needed for yet another idiotic naive attempt to enhance the software "security".
In VS 2010 there is an option to use the runtime libraries of Visual Studio 2008, which solves this problem. I don't know if there's such an option in later versions of VS.