Visual C++ 2012 Express compiled application does not work on Windows XP? - c++

I have the following C++ program which I am compiling with static linking (Multi-threaded (/MT)):
int main()
{
return 0;
}
I tried to run it on Windows XP (using Virtual Box), but it is telling me that it is not a valid win32 application!!

take a look at this:
http://blogs.msdn.com/b/vcblog/archive/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-2012.aspx
you should install vs2012 update 1. and change your toolset to xp.

Related

exe file doesn't work outside visual studio 2022

I've just installed visual studio 2022 current.Inside the environment everything works fine but i'd like to create a standalone executable. I have tried everything,downloaded microsoft c++ 2022 redistributable,the standalone build tools,tried debug and release version but when i click on the .exe of the project,nothing happens.
The program is the simple "hello world!".
To successfully run an EXE you built in Visual Studio on another computer, that computer needs to have the Visual C++ runtime installed. Install these bits on the target computer.
Alternatively, you can just link the EXE statically to the C++ runtime. More details on how to statically link your EXE at my old answer on this topic here

Visual C++ 2013 - Windows XP Sp1 C Program Not Working - Blank Command Line

just created and compiled a simple "Hello world" in C in Visual Studio 2013 for testing purpose as some service I wrote didn't work on a Windows XP machine (yes I know it's ultra old, never mind).
So I thought I'd test with "hello world". I know that I need to select a Windows XP compatible environment in the General Settings of the Visual Studio project, done that. Tried MT and MD, so static or dynamic. Both gives me the same result: Nothing. Just a blank command line. I don't get it.
Any ideas what might be missing? I'm afraid I don't have full access on the XP system, just a command line shell, that's it. But I guess that wouldn't make a real difference.
I tried other command line tools which tend to work just fine, just my own compiled ones do nothing. Source code, just so noone asks ;-)
#include <stdio.h>
#include <Windows.h>
int main(int argc, char *argv[])
{
printf("Hello World\n");
return 0;
}
Hm...aaaannoying:-)
The platform toolset should be set to XP in your project.
The VC++ 2013 runtime should be present on the test machine.
Build in release mode. Else you will have to copy the VC++ debug dlls to your applications bin folder while deploying on to the test machine
Set the _win32_winnt preprocessor to XP i.e. #define _WIN32_WINNT 0x0501
Ok, funny, as Ganesh R. rightly pointed out: It does not work with Visual Studio 2013 anymore.
So I switched to Mingw and,...perfect!

C++ custom installer (launcher)

I have written a portable program in C# with certain dependencies (.NET Framework, Visual C++ redistributable, etc) that will run on Windows XP SP3 and up.
Because of that, the program needs a launcher that will run every time before the actual program does, checking that all the required dependencies are installed. If any of the dependencies are missing, an option to download and install that dependency, will be offered. If there are no missing dependencies, then the actual program is executed.
The launcher itself is relatively simple, consisting of some registry checkup and some WinAPI calls to verify the installed dependencies.
The file structure in the end will look something like this:
C#_compiled_portable_program.exe
C++_compiled_launcher.exe // executes on any system as low as a clean Windows XP SP3 install
The problem is that I have no idea how to compile a C++ code in Visual Studio 2013 that will run with absolute bare minimum dependencies (running on the runtime libraries that come with Windows XP SP3, at least).
Take for instance the absolute simplest C++ code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello world!");
return 0;
}
If I compile this with Visual Studio 2013 with the default configurations, it will not execute on a machine that doesn't have VC++ 2013 installed, showing some nasty errors.
I looked around for similar questions and the closest I could find was
Visual Studio 2010 MSVCR dependency removal?, but the answers are either incomplete or outdated.
So, just like an installer, is it possible to compile a C++ project in Visual Studio 2013 that will run pretty much on any system?
This is not perfect, but will do for now.
This is what I did to make a C++ project, compiled in Visual Studio 2013, execute ona system that doesn't have VC++ 2013 installed.
I created a new C++ project in Visual Studio 2013, File>New>Project>Visual C++>Win32 Console Application
Then in Solution Explorer right click the project and select Properties.
Click the Configuration drop down menu and select All Configurations.
In Configuration Properties>General, set Platform Toolset to Visual Studio 2013 - Windows XP (v120_xp).
With Dependency Walker determine what modules are imported by the compiled exe (the release build, not the debug one). The imported modules should be:
c:\windows\system32\KERNEL32.DLL
c:\windows\system32\MSVCR120.DLL
KERNEL32.DLL is a system file so we don't have to worry about that, and MSVCR120.DLL is the Visual C++ 2013 Runtime Library and we need to distribute this file along with the release build. When the executable needs to load a module, it first looks at its current location for that file and then in PATH (System32, etc). If we copy MSVCR120.DLL at same location the release executable is, then the program will run even on systems without VC++ 2013 installed.
Since the project is a 32-bit application, download VC++ 2013 Redistributable x86, install it on a 32-bit version of Windows (I installed it on a fresh Windows XP virtual machine), and copy c:\windows\system32\MSVCR120.DLL.
Update:
Never mind. You don't have to distribute a copy of VC++ Runtime DLL file, you can just configure the project to link statically to the runtime library.
Here is explained how to do it. You'll still have to change the Platform Toolset though, if you plan on executing on Windows XP.

VS2012 C++ DLL compatability

I have a DLL compiled in vs10 on windows xp 32bit
Then i moved to windows 7 32bit and compiled it in vs2012, the project build target was win32.
The new compiled DLL works perfectly when i use it on windows 7, but when i run it on win xp sp3 it says the program cant find the dll error
0x8007007E
How is that possible and what settings do I have to change?
A simple workaround is to static-link the runtime modules using /MT
http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx

Visual C++11 executables and Windows XP [duplicate]

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.