Use specific version of vcredist? - c++

Is it possible in Visual Studio 2008 SP1 to target a C++ COM project to vcredist 2008 instead of vcredist 2008 SP1?
Our customers have the vcredist 2008 installed and we don't want to force them to install vcredist 2008 SP1. (thousands of computers!)

VS2008 actually, by default, continues to target the VS9 RTM redist.
What is happening in dependency checker is, when VS9 SP1 is installed, a policy file is also installed that redirects attempts to load the RTM redistributables to the SP1 redistributables.
In order to get VS9 SP1 to actually require the SP1 runtimes you need to add the following macro to your project settings or precompiled header:
#define _BIND_TO_CURRENT_CRT_VERSION 1

You can try to remove the embed manifest (look under the project settings Manifest Tool) and provide your own manifest for the application that targets the pre sp1 CRuntime versions.
You can also deploy the C-Runtime yourself, in the redist folder under x86/x64 you will find the folder of the C-Runtime (Microsoft.VC90.CRT) just copy those folders in the same folder as your exe.
Use the static C-Runtime option, so that the C-Runtime will be used as static lib, its useful if you don't have a lot of dll/exe.

Related

How to compile C++ app for Windows XP in MSVS?

As I read this article, it is enough to download most recent MSVS 2022 and then install toolset C++ Windows XP Support for VS 2017 (v141) tools [Deprecated].
After that in Visual Studio inside project properties I set this toolset. According to linked article it is enough to compile C++ app with XP support.
But after my .exe file is created if I run it on XP 64-bit SP2 then it shows error that CompareStringEx function is not found in KERNEL32.DLL.
Hence it appears that it is not enough to use this toolset. Something else is needed.
In some other places I see that one needs also to add define /D_USING_V110_SDK71_ when compiling and option /SUBSYSTEM:CONSOLE,5.01 when linking. In my project properties I also tried to add this two options, but still CompareStringEx is inside import table of final application.
As suggested by #BenVoigt, I did defines /DWINVER=0x0502 /D_WIN32_WINNT=0x0502. Also set C++ standard to /std:c++14 (I would set C++11 but this MSVS version allows to set only C++14 at minimum). Still some non-XP symbols remain in final EXE like InitializeSRWLock that is possibly used by C++11's std::mutex in my code.
Does anyone know everything what is needed in order to compile fully XP-compatible application?
Update. I managed to build working XP application by doing things above plus setting C++ CRT runtime to Multi Threaded DLL, i.e. using dynamic DLL linkage of CRT. Also as suggested by #ChuckWalbourn (down x86 or x64 redists), I downloaded older version of msvcp140.dll.
But it is very important for my project to have statically linked runtime (C++ CRT), i.e. use Multi Threaded value for Runtime field in project properties. Only if it is REALLY not possible only then I will use DLL CRT. Until then solution about how to link CRT statically are welcome, of course to produce XP-compatible EXE.
TL;DR For Window XP VC++ REDIST support, install https://aka.ms/vs/15/release/VC_redist.x86.exe on your Windows XP system
-or-
if you are doing "side-by-side application local deployment", then use the DLLs from C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Redist\MSVC\14.16.27012\x86\Microsoft.VC141.CRT.
If you want the latest bug fixes to the CRT, you can also download the REDIST for VS 2019 (16.7) per the link on Microsoft Docs.
For Windows XP targeting, you use the v141_xp Platform Toolset installed by Visual Studio (VS 2017, VS 2019, or VS 2022) which is the latest VS 2017 (v141) C++ compiler using an included Windows 7.1A SDK.
Make sure you have installed (for VS 2022) the following individual components since you are using MFC:
Microsoft.VisualStudio.Component.WinXP: C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]
Microsoft.VisualStudio.Component.VC.v141.x86.x64: MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
Microsoft.VisualStudio.Component.VC.v141.MFC: C++ MFC for v141 build tools (x86 & x64)
If you are doing DirectX development, be sure to read this blog post as well for various implications of using the Windows 7.1A SDK.
For deployment to Windows XP, you can install the latest VS 2017 Visual C++ REDIST or use VS 2019 Visual C++ up to VS 2019 (16.7). After that the REDIST DLLs themselves are not compatible with Windows XP.
On your development system with VS 2022 installed, you are going to have a newer set of Visual C++ REDIST files which are binary compatible with your v141_xp Platform Toolset built EXE, but those VC++ REDIST DLLs are not compatible with Windows XP.
IOW: If you look at a dumpbin /imports of the 14.30 (v143 version), 14.29 (v142 latest version), and/or 14.16 (v141 latest version ) copies of msvcp140.dll you will see different imports. The msvcp140.dll sitting in your C:\windows\SysWOW64 folder is going to be the 14.30 version.

how to forece mfc to use Redistributable 2013 or below

I create an Activex by vs2015 and '/clr' option. when i run it on other pc's, it need Redistributable 2015.
But Redistributable 2015 not installed on win8.1 and win2012 server. but Redistributable 2013 installed on them.
How can i force mfc to use Redistributable 2013? (or better solution)
i checked this but not helpful.
and changing Platform Toolset to Visual Studio 2015 - Windows XP (v140_xp), generate some errors in a hello-word project
i use Activex because i need events
it use 'clr' option, because i use a managed dll in this activex
Redistributable 2015 log Error 0x80240017: Failed to execute MSU package apparently for Windows8.1-KB2999226-x64.msu
Windows8.1-KB2999226-x64.msu standalone installer say The update is not applicable to your computer.
installing a Net4.6 suggested, But this installer blocked by The update corresponding to KB2919355 needs to be installed before you can install this product on Windows 8.1 or Windows Server 2012 R2 and this update is 690.8 MB, and that MB blocked me.
You can not switch Visual Studio to use older toolset. You have to either - install older version of MSVC, or link your program statically, removing need in the redistributable altogether. To staticaly link your project open its Release properties, navigate to the C++/Code generation node and select Multithreaded instead of Multithreaded Dll for the Runtime option.

Is MSVCP140.dll OS/version-dependant?

So I tried to run my program in another computer, as you'd expect from the title, the computer was missing msvcp140.dll - I downloaded it from the internet (didn't have other options at the time) and it didn't work.
Aside from 32-64 bit versions of said .dll, are there different versions for each version of visual studio and/or for each Windows' version (7, 8, 10)?
I would rather not have make users install Visual Studio on their computer just for my program.
msvcp140.dll is a Dynamic Link Library (DLL) that is a part of Microsoft Visual C++ component. Your machine might not have the Microsoft redistributable for Visual C++.(I assuming you are using VC++ compiler). Since the other machine does not have MSVS installed, there is no guarantee it has the redist installed. Just install the appropriate redist package from your Visual Studio version to avoid error. msvcp140.dll is Microsoft Visual C++ version dependent.
If you don't want to redistribute MSVC DLLs with your application, you can make a static build of your application.
In Project Settings -> C/C++ -> Code Generation -> Runtime Library -> Select /MT or /MTd (debug)
A statically linked module will not require any MSVC DLLs (other than omp140, if you use OpenMP)
(The downside is that your EXE will become larger)

How to distribute VC redist with an MSI when using Visual Studio 2015?

We are just switching to Visual Studio 2015, but we have found a problem in deployment of our application.
We use Wix/MSI for deployment and until now we were using merge modules for distribution of VC redist.
But now we have a problem that our application requires ucrtbase.dll. There is a new Universal CRT according to this article and it is not contained in any merge module.
In above-mentioned article they are saying that:
There will not be a merge module for the Universal CRT. If you currently use the CRT merge modules and still want to deploy the Visual C++ libraries centrally, we recommend that you move to the above mentioned Windows Update package or to the VCRedist. Alternatively, you may choose to link statically to the Universal CRT and the Visual C++ libraries
Does this mean that we cannot distribute C++ runtime with our MSI as it cannot run executables (VCRedist.exe)? Or is there a way to compile our project in Visual Studio 2015 so it will not require this Universal CRT?
Thank you in advance.
If you use WiX, you could switch to Burn and run the VC Redist packages as part of the setup.
The article you referenced also says that app-local deployment of the Dlls is supported, so you could install the appropriate Dlls without needing redist.
I would use Burn to install the official redist - it's the only way that Mocrosoft can service those Dlls if there are issues. If you use app-local or your own copies of the Dlls you may need to ship patches or upgrades if there are security issues in those Dlls.

Are there any side-effects of using macro _BIND_TO_CURRENT_VCLIBS_VERSION?

We are porting a VC++ project from Visual Studio 2003 to Visual Studio 2008 SP1(9.0.30729.4148). The dependent external libraries are also
compiled with Visual Studio 2008 SP1.
MainApp - Main application Compiled with VS SP1 9.0.30729.4148
ExtStaticLib1 - External static library compiled with VS SP1 9.0.30729.4148
ExtDynamicDll1 - External DLL compiled with VS SP1 9.0.30729.4148
There are two deployment scenarios for the Main application:
Machine with User Admin rights:
We recommended to put a pre-rquisite to install Visual Studio redistributable package before using the application MainApp. This works well as user has the admin rights and installing redistributable package has no issues. Application links to the VC redist DLLs in WinSxS folders automatically.
Machine with non-admin user:
This scenario is problematic. The user is not having the admin rights. Hence, it is not possible to install VS2008SP1 redistrtibutable package.
We are doing following to solve this:
Compile MainApp targets with macro _BIND_TO_CURRENT_OPENMP_VERSION ( for all the projects in MainApp).
Distribute the VS2008SP1 redistributable DLLs as private assemblies and copy them in application install directory.
Questions:
Is there any side-effect of using the flag _BIND_TO_CURRENT_VCLIBS_VERSION (Specially when both VC redistributable package and private VC redist assemblies exists together)?
We do not have much control on the external libraries ExtStaticLib1, ExtDynamicDll1 and hence, they will not be compiled with macro _BIND_TO_CURRENT_OPENMP_VERSION. But they are already compiled with VSSp1. Will there be any issue with this setup?
Will there be any issue if there is a newer version of VS redistributable available (newer than 9.0.30729.4248).
Thanks.
I would avoid using any of the BIND macros. You'll get into troubles sooner than later.
Even if you distribute the VC runtime dlls as private assemblies, you can't be sure that the user doesn't have them installed already with some other app.
One problem that arises is that you can end up with a manifest that references multiple c-runtime versions. Here's an open issue about this (FYI: I had that very same issue!).
So if there's no reason that would force you to only use a very specific version of the c-runtime and not the latest compatible one, then don't use those define macros!
Found this blog resource which has answer to your question.
Refer section which says "Updates, patches and service packs"
http://helgeklein.com/blog/2010/03/deploying-visual-c-runtime-files-as-private-assemblies/