Building c++ project for Win XP in MSVC 2012 - c++

I have a console application that I need to use on Windows XP. Also i'm using MSVC 2012 as an IDE. Problem, that when i run it on Win XP (SP3) i receive error message that this application is not a valid win32 application.
UPD:
After talking care about suggestions in the comments to this question, i've updated my question.
What does use my application:
Urlmon.h/urlmon.lib
boost::program_options
c++11's regex
What i've already tryed:
Build test application like "Hello, World!". It works on target Win XP
Install Update 3 for MSVC 2012 & update 3 redist. to target machine
Build app with static linking (/MT)
Dependency walker shows 3 messages:
Missing WER.dll
Missing IESHIMS.dll
Unresolved C function "WNetRestoreConnectionA"
As far as i see nothing of listed in dependency walker should affect my app, but it still fail to load with error "not a valid win32 application".
Does anyone have ideas why>

The v110_xp toolset automatically specifies the SUBSYSTEM's MRV ("5.1" (WindowsXP)) but not the SUBSYSTEM
That was the problem. I've set SUBSYSTEM to "/SUBSYSTEM:CONSOLE" in project settings & problem with target Win XP dissapeared. Thanks everyone for comments.

As I know, MSVC 2012 toolset do not support windows XP. But you can use MSVC 2010 toolset in IDE 2012. Or use toolset v110_xp forom Visual Studio 2012 Update 1(I didn't try it).
This link may help
http://blogs.msdn.com/b/vcblog/archive/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-2012.aspx?Redirected=true

Related

C++: MFC Application on both Windows 10 x64 & Windows 7 x64

I'm building MFC Application with CLR which can run on windows 10 x64 & windows 7 x64 and execute without installing Visual Studio.
First, I've tried to find a solution for app without installing visual studio.
After some works on google, I found some clues to this issue.
Release build doesn't require installing Visual Studio.
I was building the project on windows 10 x64. So the release version can work on other windows 10 pcs without Visual Studio.
But it can't work on Windows 7.
So I've got stuck in search on this issue until now and I found something.
"Build applications for both Windows 7 and Windows 10 with Visual Studio 2015" is a thing I found here.
The answer is right thing I've tried.
On their comment, I saw one word - CMake.
I'm not sure that I can accomplish my solution with this - CMake.
Is there someone to told about this thing?
Or anyway to fix this issue?
Thank you.
CMake won't help you.
I think you'll need to install Visual C++ Redistributable for Visual Studio 2015 on any machine where Visual Studio was not installed, if the redistbutable package was not installed yet.
You also need to use .NET framwork which installed on both machines, I guess .NET 4 is good enough.
EDIT:
Try to run your exe from a console, and check if there is some print for missing dll or something.
Anyway, you can use dependency walker to check if you're missing some dlls, (download the x64 version) drag&drop your exe into it and check what prevent it from run.
Now, I found right solution about this m own question.
As a matter of fact, #SHR is helpful for this answer, but there's something to modify for right solution.
Installing .NET 4.0 is right and it's mandatory for working on Windows 10 & 7 x64.
But "Visual C++ Redistributable for Visual Studio 2015" should not be necessary.
Without these packages, the app can executes on windows 7 & 10 x64.
Of course, the app requires some dlls in C++ Redistributable packages. But not all.
So I put dlls the app requires at the same directory of .exe file.
That's all.
There's no other requirements.

C++ app built on Windows 7 (using VS2010 IDE and VS2008 toolset) runs on Windows 7, but not on Win XP

I have a C++ application, which is built on Windows 7 using VS 2010 IDE against VS2008 toolset. I have verified that it depends on msvc*90.dll.
The problem occurs when i move it to XP professional SP3 machine. I have installed the 32-bit vs 2008 redistributable package too.
However, the application fails to run. No error is reported. Nothing is logged into system even viewer as well.
Any hints?
PS: I have seen the following threads already.
Program Built on Win7 won't run on WinXP
How do I compile for windows XP under windows 7 / visual studio 2008
Have you checked the DLL in that Windows XP system with Dependency Walker. This may help you find if you are not missing another dependency or not dealing with side by side execution problems.
This issue is resolved now. The problem was not related to dependencies. Instead, it was some directory not existing in the file system.

Visual Studio 2012 Project targeting Windows XP using MFC

I have recently acquired source code from a VS2005 project that uses the MFC library. Firstly I upgraded the project to VS2012 and I can now successfully build and run the software on Windows 8. Next, I wanted to deploy the software on a Windows XP machine.
I have set the Platform Toolset to build to Windows XP (using the v110_xp option) and I have installed the 'Visual C++ Redistributable for Visual Studio 2012 Update 1' on the target machine. When I run the software, nothing appears to happen. Via some logging functions I can determine that a call to LoadFrame(IDR_MAINFRAME) causes an exception in kernel32.dll. I can't debug any further in to LoadFrame as remote debugging on Windows XP is not available in VS2012.
Any ideas what may be going wrong? Is the Visual C++ Redistributable package the correct version to be installing on the target machine? What should I be trying next?
UPDATE
My project is already set up to use the 7.1 SDK and has minimum required version set to 5.01 in linker options.
If I use InstallShield to generate an installer and include the MFC, CRT and ATL redistributables, the installer works and my program now runs on Windows XP. My understanding of the redistributables is that they simply copy the relevant dll's in to the system32 folder (or equivalent)? Is that correct?
However, if I simply copy the files over, run the vsredist_x86.exe or use Inno Setup to install the software & dll's, my program no longer works.
I believe you have read this blog. In summary, you need to use the 7.1 SDK, and you need to set minimum required version to 5.01 in linker options.
Using the working InstallShield project and the not-working Inno project I was able to determine that the real culprit here was an unregistered msxml4.dll. The error I was receiving gave no real clue to this outcome but I got there eventually...
regsvr32 msxml4.dll

VS 2012 - XP Issues

I installed VS 2012 Professional and the XP update as well. I built my project with v110_xp as the platform toolset on VS 2012. My project's .msi package is installing fine on Win 7 but failing on Win XP SP3. The error reported on XP SP3 is -
"The procedure entry point FlushProcessWriteBuffers could not be
located in the dynamic link library Kernel32.dll".
While the same project built from VS 2005 is installing fine on XP SP3. I am not sure what is going on VS 2012. _WIN32_WINNT is set to 0x0501. Can some one please guide as how to resolve the problem ?
Any help is highly appreciated,
Mahesh.
Yes, the C Runtime has a dependency on FlushProcessWriteBuffers(). The updated version of msvcrt110.dll and libcmtl.lib, the ones you got along with the update, no longer directly link to the function, they use GetProcAddress() to find it and limp along if it is missng. So you should never get this error.
So very high odds that you deployed the wrong version of msvcrt110.dll, an old one instead of the updated one. You can find it back in c:\windows\system32, look at the properties. Mine is version 11.00.51106.1, dated 11/5/2012. A separate installer is available for it here.
The VS2012 runtime that you are installing uses functions that are not present available in XP. See this MS article: Targeting Windows XP with C++ in Visual Studio 2012 which explains more and provides some workarounds.
Update 1 for VS2012 resolve the problem.
But Update 1 isn’t just about new Windows platforms. It also enables you to target Windows XP with native C++ applications in Visual Studio 2012.
If you are building with update 1 and still encountering problems then I suspect that you are installing an out of date runtime. You need to deploy the runtime delivered with update 1.
You can solve this by including the VC11 merge modules from your development machine(program files\common files\merge modules) in your installer. It's easier than having to run the redist exe in your installer.
If you use WIX: merge module addition
I've tested on server 03, xp64 and xp32.

How to compile VC++ 2010 projects using Visual Studio 2012 and Windows SDK 7.1

I have a lot of projects done with VS2010 in C++. Now we have switched to VS2012 but we want to continue building the projects with the VS2010 runtime (we need to support Windows XP).
To our understanding this could be possible using Windows SDK 7.1 as the VC compiler is there so we installed it. VS2012 recognized the SDK and now we have a Platform Toolset named Windows7.1SDK.
The problem comes when building the projects as some projects are returning a:
error MSB6006: "CL.exe" exited with code -1073741515.
Also, projects depending on the MFCs are failing too. MFCs aren't available with Windows SDK? Does this mean that we need to buy VS2010 licenses to install them on machines with VS2012 just to build using the VS2010 compiler?
Thanks in advance.
Looks like it's not possible at all, mainly because nothing but VS2010 is deploying the MFC libraries and we have a lot of projects using them.
We'll have to buy licenses for VS2010 and VS2012 :S
I would try raise the msbuild verbosity level (it is in Tools->Options->Project and Solution-> MSBuild) and check out the command of CL.exe with full parameters. Then check if it is different from what you saw on VS2010.
In fall Microsoft will release an update to support windows xp in visual studio 2012, you can read more in this MSDN blog:
http://blogs.msdn.com/b/vcblog/archive/2012/06/15/10320645.aspx