How do I compile for Windows XP with Visual Studio 2012? - c++

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.

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.
Download link
Blog article containing additional information

Two things should be done:
Configuration Properties → General page, change Platform Toolset to: Visual Studio 2012 - Windows XP (v110_xp);
Menu Linker → System. 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

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

Related

Windows SDK Version setting in Visual Studio 2017

I have a c++ project that compiles well under Visual Studio 2013.
Today I installed Visual Studio 2017 Professional Edition, then there's a new setting in project settings > General called "Windows SDK Version", by default is 10.0.16299.0. Since I'm compiling windows desktop programs for targeting Windows 7 systems, I changed it to 8.1, is this correct?
Generally speaking, a Windows SDK supports its "main" version and also the previous ones, but you need to specify what Windows version your program will need. In fact, you're better off doing so or else you can inadvertently use features not available in the version you want to support.
Given an SDK, you indicate which older Windows version to target by defining the WINVER and _WIN32_WINNT macros somewhere in your project files or in the C/C++ Preprocessor project settings in Visual Studio.
For example, the following definitions target Windows 7:
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
For more information, see Using the Windows Headers and Modifying WINVER and _WIN32_WINNT
Indeed I raised this issue because my freshly installed Visual Studio could not build the VM because SDK 16299 is now indeed the default. It's mentioned here:
https://en.wikipedia.org/wiki/Microsoft_Windows_SDK.
.
Also MS does not make finding older SDK's very easy. You have to click through to another page all the way on the end of this page:
https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
Even though I googled on "Microsoft Windows SDK 15063".
.
So all-in-all it's now a small chore for newbies to get up and running on the VM. To start, I think it should be made as easy as possible. (Complexity will come soon after that :)).
.
PS I'm not sure about Windows 7 compatibility. But the current VM SDK is also listed as being for Windows 10.

Visual C++ application won't run on windows 7

I am using Visual Studio Community 2015 and I wrote some simple Win32 demo application which should download file from internet and execute two HTTP GET requests.
I am using functions like InternetOpenA, InternetConnectA, HttpOpenRequestA, URLDownloadToFile, etc.
Only thing that I have changed in settings is Platform Toolset to Visual Studio 2013 (v120) and my targetver.h file looks like this:
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <WinSDKVer.h>
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <SDKDDKVer.h>
However, it runs on my Windows 10 computer, but it does not run on windows 7. It says: Missing MSVCR120.dll file. I can install appropriate C++ Redistributables but that is not solution that I need.
Is there any other options I need to include when I compile so I can avoid this error?
To avoid your application needing a separate runtime DLL, in the project settings, look under:
C/C++ > Code Generation > Runtime Library
and choose multi-threaded, rather than multi-threaded DLL.
You do not need to change the platform toolset.
In my project, that I compile with VS 2017 and want to run all the way down to Vista, I do the same as you, but without the first #include <WinSDKVer.h>. I just set the _WIN32_WINNT macro to 0x0600 and so far it's working fine.
I target the Windows 8.1 SDK, and use MFC, if that helps.
I've used dependency walker in the past to diagnose dll dependencies. Hopefully it's something silly like the 32-bit or 64-bit runtimes being missing.
As keith recommended in his answer, you can also try static linking the vc runtime (/MT[d] under C++/Code generation/Runtime Library) so that it doesn't need to load the runtime as a dll. Note that this is not the recommended option, since the VC runtime cannot be patched by Windows Update if it's burned into your executible.

Visual Studio 2010 win32 compiled application does not work on windows xp

I'm working on a project that should run on all windows platforms. It is written in c++, using only the Windows API. When I compile it in Visual Studio 6 on Windows XP, I can run it on Windows XP. When I run it in Visual Studio 2010 and run it on Windows XP it did not work. I did install vcredist2010_x86, vcredist2010sp1_x86 and .NET versions 3.5 and 4.0 on Windows XP SP3. But it still doesn't work. I added the following preprocessor symbols to my project:
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#define NTDDI_VERSION 0x0501
but it still doesn't work. My VS 2010 platform toolset is v100.
Question: What do I need to do to compile an application using Visual Studio 2010, that can be executed on Windows XP?
I'm using VS2010_sp1 on window_7_sp1_x64 and with 'release' mode.
I added #define previous to my include section.
And I've tested NTDDI_VERSION to 0x05010300 but problem is still alived! The error, showed by win_xp is:
"program.exe has encountered a ploblem and needs to close."
At all, I think, program needs dll or something to install on windows xp to run correctly!

MS Visual Studio 2012 Express for Windows Desktop - Targeting Windows XP

I have recently upgraded from Visual Studio Express 2010 to Visual Studio 2012 Express for Windows Desktop. I'm aware of the previous lack of compatibility targeting Windows XP, but thought this was resolved by Update 1 (which I have installed).
However, I'm still having difficulty targeting Win XP with the C++ applications I have compiled using 2012 Express. I have set the Platform Toolset to "Visual Studio 2012 - Windows XP (v110_xp)" but this makes no difference. When I try to run my compiled application on my Windows XP system (I run Windows XP via VirtualBox), I get an the error that my application "is not a valid Win32 application."
I have also tried setting the CLR Support to "No Common Language Runtime Support" and the Runtime Library to "Multi-threaded (/MT)".
Even with a very basic blank C++ project using the following code, I just can't get it to run on XP:
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#define NTDDI_VERSION 0x0501
#include <iostream>
int main()
{
std::cout << "TEST" << std::endl;
std::cout << std::endl << std::endl << "Press ENTER to close this window.";
std::cin.get();
return 0;
}
Can anybody tell me where I'm going wrong with my compiler/project settings?
P.s. I have installed the MS VC++ 2010 and 2012 redistributable packages on my XP virtual machine. Applications that I compiled with Visual Studio Express 2010 work fine on my XP virtual machine.
Check your project's "Configuration Properties -> Linker -> System -> Subsystem" properties.
If blank, fill it with (/SUBSYSTEM:CONSOLE) or (/SUBSYSTEM:WINDOWS).
This works:
Configuration Properties -> Linker -> System -> Subsystem =
/SUBSYSTEM:WINDOWS
Configuration Properties -> General -> Platform Tool Set ->
SubsystemVisual Studio 2012 - Windows XP (v110_xp)
Using Visual Studio 2012 Express Update 3.
Use GNU GCC tool chain, bro, that redistrebuted with mingw. MSVS actualy just minimize dependencies, but some of them still stay in exe. Just compiling in gcc suports full static linking, with small exe size and stable compatibility.
The message is indicating that your build isn't producing a 32 bit application--if it were a version dependent API, for example, you'd see another error indicating that the symbol can't be found. Since you have indicated that you are using the correct target platform in the configuration manager, check your property explorer to make sure you don't have conflicting arguments or defaults. If you see link with the option /MACHINE:X64, then you've found the problem.
If that doesn't work, I suppose you could try running Sysinternals process explorer to see which cl/link are actually being launched with which arguments. Hope that helps.

Explorer thumbnails (winXP)

I have a file format I need to be able to show in explorer thumbnails. Since the target system is windows XP, the Vista PreviewHandler API will not be suitable. Ill be using c++.
How would I do it?
You'll need to register a shell extension for your file type. The extension contains code that extracts/generates the thumbnail by implementing the IExtractImage interface.
See: IExtractImage Interface on MSDN
https://github.com/reliak/moonpdf/tree/master/ext/sumatra/src/previewer is perfect example.
To build both x86 and x64 versions of DLL I use VS 2010 with SP1 along with Win7 x64 SDK (for <thumbcache.h>) installed on Windows 7 x64. Builded DLLs works fine on Win7 and Win10 of either bitness.
Also don't forget /MD linker flag to avoid necessity to install Microsoft Visual C++ 2010 Redistributable Package (x86) on WinXP.
Next lines may be added to "targetver.h" to avoid import and using of new functions from newer versions of Windows system DLLs (say, there is no RegDeleteTreeW in WinXP's advapi.dll):
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#include <winsdkver.h>
#include <SDKDDKVer.h>
Additionally it has implementation of previewer for some file formats, but related interfaces can be completely omitted in your implementation.