24

Ok, so I'm using Visual Studio 2012 in Windows 7 x64 for programming and compiling. My application works fine there, but when I try to execute it from a Windows XP SP3 Virtual Machine, I get "xxxx.exe is not a valid win32 application" right away.

The application is being compiled with static linking, that is, with /MT. I have set _WIN32_WINNT to 0x0501 in targetver.exe; the configuration manager is set to Win32 and the target machine in the Linker advanced options is set to MACHINEX86.

My targetver.h looks like this:

#include <winsdkver.h>

#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#define NTDDI_VERSION 0x0501

#include <SDKDDKVer.h>

I also tried compiling with /MD and installing .NET Framework, but that didn't help either.

I'm clueless, and I could really use some help as I need to have it working for Windows XP.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
WiperWoper
  • 318
  • 1
  • 2
  • 8
  • 4
    VC++ 2012 RTM does **not** support WinXP. Have you installed the [CTP of WinXP targeting with VC++ 2012](http://aka.ms/ms3oxw)? See [this blog article](http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx) for more information. – ildjarn Oct 29 '12 at 22:47
  • Oh well, that explains everything. Could have saved me a few hours trying to get it to work. I'll have a look at these links, thank you. – WiperWoper Oct 29 '12 at 22:49
  • Please note that `Visual Studio` is not a programming language; it's a development environment. It supports many languages (C#, VB.NET, C++, etc.). The **language** you're using is C++, and that's what your question should address. There's an important difference between a language and and IDE most of the time. :-) – Ken White Oct 29 '12 at 22:58
  • Yes, I know that Ken. I'm sorry if the question was in any way misleading. I did not intend to say Visual Studio was a programming language, I just wanted to point out it was my development environment as you said, as it seemed to be the cause of my problem. Thanks anyway. – WiperWoper Oct 29 '12 at 23:06
  • Just tried the [CTP for WinXP Targetting](http://www.microsoft.com/en-us/download/details.aspx?id=34818) (hopefully I did the formatting right with that link) and it worked flawlessly. Guess I won't need to switch back to Visual Studio 2010. Thank you very much, I'd upvote you if I could; sadly, I can't. Yet. – WiperWoper Oct 29 '12 at 23:30
  • Related question, focusing on why this happens: [What is special about the executables...](http://stackoverflow.com/q/7702463/145173) – Edward Brey Jan 08 '14 at 01:46

3 Answers3

24

VC++ 2012 RTM did not support Windows XP – that support came later in 2012 in Visual Studio 2012 Update 1.

The CTP of Windows XP targeting with VC++ 2012 could be installed, but you would have to link the CRT statically in order to deploy. See this blog article for more information.

Visual Studio 2012 Update 1 added official support for running applications built with VC++ 2012 on Windows XP as well as the ability to link the CRT dynamically.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ildjarn
  • 62,044
  • 9
  • 127
  • 211
  • I have the same problem with my application, but I'm using visual studio 2015. But I don't know how t compile with a static link. – Bart Oct 09 '15 at 09:40
  • 1
    @Bart : With VC++ 2015 you don't need to link statically (though you can if you like, of course). Instead you need to go into your project properties and change the 'Platform Toolset' option to 'Visual Studio 2015 - Windows XP (v140_xp)'. If that option isn't present then you need to rerun VS setup and customize the installation options to include WinXP support. – ildjarn Oct 09 '15 at 18:05
  • 1
    (I am not sure if the past tense form is the correct way (chosen for the presumed non-availability of the RTM), but an answer should not be a historical account of how it changed (that belongs in the revision history), and it should not have meta information (e.g. why the answer changed - that is what comments are for). An answer should be the best current version. Feel free to revert or put it into some other form.) – Peter Mortensen Oct 31 '19 at 12:07
7

Two things should be done:

  • Configuration PropertiesGeneral page, change Platform Toolset to: Visual Studio 2012 - Windows XP (v110_xp);

  • Menu LinkerSystem. Change Subsystem to: Console/Windows.

A detailed explanation is here: http://software.intel.com/en-us/articles/linking-applications-using-visual-studio-2012-to-run-on-windows-xp

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

When you generate the EXE file, the version for 32-bit will be in the project folder bin\x86\Release.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cesar
  • 1
  • At the time of the question (2.5 years ago) VS 2012 (The production release without any updates) couldn't target XP out of the box. Updates since then have long since resolved the problem. – Michael Petch Oct 07 '14 at 18:55
  • 1
    @MichaelPetch: The updates made a solution available, but you still have to switch the toolchain in project settings. So it still doesn't "target XP out of the box". – Ben Voigt Oct 30 '14 at 19:46
  • @BenVoigt : I tend to disagree. It is a project settings. That would be like saying that anything that isn't default for a project isn't out of the box. Or that optimizations aren't out of the box. If you had to go out of your way to download more files from MS and integrate them into the environment then I would't consider them out of the box. For instance I don't consider creating ATL and WTL projects out of the box for that reason. – Michael Petch Nov 01 '14 at 18:24
  • @MichaelPetch: Ok, I'm just saying this is an issue we should expect to keep seeing, because it isn't "right by default". – Ben Voigt Nov 01 '14 at 18:27
  • @BenVoigt : I don't disagree on that point. I haven't downvoted or voted to close the question for that reason. Had the question been asked today the answers would be different since it would be a matter of saying they should upgrade their VS2012 to the latest Service Pack and use project settings to turn on the desired behaviour. I responded to this thread late because this answer came late. – Michael Petch Nov 01 '14 at 18:32