1

This is similar to the question here, but it pertains to the unmanaged C++ assemblies, instead of managed .Net ones.

Assuming that my application directory has its own Visual Studio Redistributable 2015 runtime DLLs ( I redistribute the runtime at app directory, just in case the client machine cannot install the VC++ redistributables from Windows update), and the client machine also has Visual Studio Redistributable 2015 package installed. Which one will get loaded, the vcruntime140.dll located at the application directory, or the vcruntime140.dll installed?

Similarly, my application directory has its own set of Universal C Runtime ( Again, I do this out of the reason that some client machines cannot install Universal CRT due to various reasons), and in the case the client machines also have Universal CRT installed, which one will get loaded, the installed Universal CRT DLLs, or the ones at my application directory?

For Windows 10 and Universal CRT, I know that the Universal CRT in the system directory is always used, even if an application includes an application-local copy of the Universal CRT. It's true even when the local copy is newer, because the Universal CRT is a core operating system component on Windows 10.

But I am not sure about other Windows 10, and above Visual Studio C++ redistributable package.

Thus I am looking for answers on all supported Windows versions, including Windows 7, Windows 8.1 and Windows 10.

Note: I am calling the unmanaged C++ assemblies from .Net, if that matters.

Graviton
  • 81,782
  • 146
  • 424
  • 602
  • Difference Between Assembly and DLL: https://stackoverflow.com/a/674426/6345 – Johann Gerell Oct 31 '19 at 06:51
  • Perhaps linking statically with `libvcruntime.lib` is the way to go? – Ted Lyngmo Oct 31 '19 at 07:58
  • @TedLyngmo no it's not because I obtain the C++ libraries from other third parties – Graviton Oct 31 '19 at 07:58
  • Deploying the UCRT yourself is a gross mistake. Yes, it is core OS component and the loader has secret knowledge of it. Which is why the normal DLL lookup rules don't apply. The essential problem is that the local copy may actually be used. That happens on an unmaintained OS, you'll have no idea why your program crashed. No critical updates, no security fixes, for all you know it is infected to oblivion. The redist version is only meant to get a program running on XP or Win2003, versions that are no longer maintained. – Hans Passant Nov 05 '19 at 20:26
  • @HansPassant, the problem is that there are machines ( run on Windows 7) cannot [download and install UCRT and VC++ redist.](https://social.msdn.microsoft.com/Forums/vstudio/en-US/1969e78b-f2cd-4d6a-97d4-a378e613d0ba/installation-gets-stuck-on-quotupdate-for-microsoft-windows-kb2999226quot?forum=vssetup). So I need to find a workaround – Graviton Nov 06 '19 at 00:48
  • So their machine is already so messed-up before they try to use your program and you want to fix that? You can't support it, tell them to re-image it. – Hans Passant Nov 06 '19 at 07:49
  • @HansPassant since Microsoft is bending backwards in supporting these machines , I believe that I can, too – Graviton Nov 06 '19 at 11:47
  • You are missing the point: you can't. You'll have no idea whatsoever why the program crashed. You need to support the program you know before you support a machine you know nothing about. I'm fully aware you don't want to hear it, no comment necessary, but it is important to anybody else that reads this question. – Hans Passant Nov 06 '19 at 12:00

1 Answers1

0

The load order for your CRT dll's are in the following order:

  • Directory from where app was started
  • Current directory
  • System directory
  • Windows directory
  • Path environment variables.

You can place your runtime dll's in the app's current dir, and they should load. If you are compiling on Windows 10 and don't want UCRT refrences, compile with /NODEFAULTLIB

Or, you can statically link to the CRT libraries using the compile option /MT

Arush Agarampur
  • 1,340
  • 7
  • 20
  • As explained in the question, your answer is wrong when it comes to Windows 10 and UCRT because no matter what, the copy in the windows system will get loaded first – Graviton Nov 06 '19 at 00:49
  • This is not strictly wrong, it's just missing some context. The newer CRTs are not loaded directly as DLLs, but via API-Sets like "api-ms-win-crt-runtime-l1-1-0.dll", which have a [redirection mechanism](https://lucasg.github.io/2017/10/15/Api-set-resolution/) – PeterT Nov 09 '19 at 11:04