42

I have small C/C++ project in Visual Studio 2012 RC

This applications parses the argv and then calling another .exe file with ShellExecute

My application works perfect on Windows7 but on Windows XP x86 trhows Is not a valid Win32 application error.

I have compiled it with Mutli-thread(/MT) and Win32 Platform

This is my #includes

#include <string>
#include <iostream>
#include <Windows.h>
#include <fstream>
#include <cstdio>
#include <vector>
#include <windowsx.h>
#include <shlobj.h>
#include <stdio.h>
#include <tchar.h>
#include <direct.h>

Thanks

rotoglup
  • 5,223
  • 25
  • 37
user525717
  • 1,612
  • 5
  • 28
  • 40
  • 1
    Did you compile a x64 application? – rekire Jul 03 '12 at 06:37
  • Is the "another exe" a 64-bit application? Did you recompile it for your 32-bit environment? – John Lyon Jul 03 '12 at 06:38
  • 2
    @user Though this is a very late comment, have you checked whether `"Configuration Properties -> Linker -> System -> Subsystem"` is set ? If it is blank, set it to the appropriate option, rebuild and check the executable on XP. – Mahesh Oct 11 '12 at 00:06
  • @user After checking my above comment, if still you get the same error, [install the update](http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx) MSFT recently released. – Mahesh Oct 11 '12 at 00:20

8 Answers8

50

It's Feb 2013, and I can now target XP in VS2012 by setting:

Project Properties -> General -> Platform Toolset to:

Visual Studio 2012 - Windows XP (v110_xp)

You will have to redistribute the msvcp110.dll libraries et al with your application, which are found here: "<Program Files>\Microsoft Visual Studio 11.0\VC\redist\x86\Microsoft.VC110.CRT\"


Update Aug 2015 with Visual Studio 2015

There seems to be quite a selection now. I was able to compile application in VS2015 using Visual Studio 2015 - Windows XP (v140_xp) setting. To make it actually run on Win XP I had to deploy (copy alongside application) msvcr100.dll for Release build and msvcr110.dll and msvcr100d.dll for Debug build (note there is a difference in numbers 100 and 110, also debug lib msvcr100d.dll may not be redistributable) Targeting Windows XP with Visual Studio 2015

oleksii
  • 35,458
  • 16
  • 93
  • 163
noelicus
  • 14,468
  • 3
  • 92
  • 111
  • 8
    That's v helpful thanks. It's worth noting you don't need to redistribute the dlls if you go to c/C++ => Code Generation => Runtime Library and choose to compile in your crt. E.g. with the /MT option. – TooTone Jun 15 '13 at 12:55
  • Now MSVC 2015 and 2017 don't support the static linking for the CRT. – Raindrop7 Sep 28 '17 at 12:54
43

VS 2012 applications cannot be run under Windows XP.

See this VC++ blog on why and how to make it work.

It seems to be supported/possible from Feb 2013. See noelicus answer below on how to.

Community
  • 1
  • 1
RedX
  • 14,749
  • 1
  • 53
  • 76
6

While seleted answer was right time ago, and then noelicus gave correct update regarding v110_xp platform toolset, there is still one more issue that could produse this behaviour.

A note about issue was already posted by mahesh in his comment, and I would like to highlight this as I have spend couple of days struggling and then find it by myself.

So, if you have a blank in "Configuration Properties -> Linker -> System -> Subsystem" you will still get the "not valid Win32 app" error on XP and Win2003 while on Win7 it works without this annoying error. The error gone as soon as I've put subsystem:console.

Andrey Sorich
  • 73
  • 1
  • 5
  • I got bit by clearing Linker/System/Subsystem thinking that it would fall to the default. It works, but only on Vista+. Breaks XP with the "Not a valid Win32 app" error. Thanks @andrey for documenting. – CoreyStup Aug 09 '16 at 19:40
4

There are at least two solutions:

  1. You need Visual Studio 2010 installed, then from Visual Studio 2010, View -> Solution Explorer -> Right Click on your project -> Choose Properties from the context menu, you'll get the windows "your project name" Property Pages -> Configuration Properties -> General -> Platform toolset, choose "Visual Studio 2010 (v100)".
  2. You need the Visual Studio 2012 Update 1 described in Windows XP Targeting with C++ in Visual Studio 2012
Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153
  • Visual Studio 2012 Update 2012 doesn't seem to fix this issue. Have Microsoft issued a fix yet? I am using a QT project so can't set the Platform Toolset ( see this question: http://stackoverflow.com/questions/14657766/visual-studio-2012-platform-toolset-set-incorrectly ), so I'm a little stuck. – gollumullog Feb 14 '13 at 21:34
  • @gollumullog Hi, I am not familiar with QT, why can't you change the Platform Toolset? – Alessandro Jacopson Feb 14 '13 at 21:46
  • QT projects have a different "Property Page" than normal Visual Studio projects. Basically they use qmake.exe to generate a set of makefiles. I tried following the command line instructions on "http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx" but it isn't working for me. If I find a solution I'll post to the above question. Cheers – gollumullog Feb 18 '13 at 20:56
  • I fixed my issues, the command line changes for QT are: win32 { QMAKE_LFLAGS += /SUBSYSTEM:CONSOLE,5.01 QMAKE_CXX += /D_USING_V110_SDK71_ LIBS *= -L"%ProgramFiles(x86)%/Microsoft SDKs/Windows/7.1A/Lib" INCLUDEPATH += "%ProgramFiles(x86)%/Microsoft SDKs/Windows/7.1A/Include" } – gollumullog Feb 18 '13 at 21:59
1

For me, this helped: 1. Configuration properties/General/Platform Toolset = Windows XP (V110_xp) 2. C/C++ Preprocessor definitions, add "WIN32" 3. Linker/System/Minimum required version = 5.01

Matsk
  • 11
  • 2
1

I had the same issue on Windows XP when running an application built with a static version of Qt 5.7.0 (MSVC 2013).

Adding the following line to the project's .pro file solved it:

QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
karlphillip
  • 92,053
  • 36
  • 243
  • 426
-1

I believe this error can also be thrown if your project is targeting a framework version that is not installed on the server you are deploying to.

David H
  • 21
  • 2
-1

I got this problem while launching a VS2013 32-bit console application in powershell, launching it in cmd did not issue this problem.

Zac
  • 4,510
  • 3
  • 36
  • 44