admin管理员组

文章数量:1406911

In order to decrease our app's installer size and do not force the user to download MSVC runtime redistributable installer, we include all the MSVC runtime DLLs we need (and only them) into our installer using the following technique.

All was working fine during many years until now. Recently we've switched to use MSVC2022 and 14.42.34433.0 version of the runtime (pretty new one). Now, we're getting crash dumps from our users. Not too much (about 1 per 1000 users) with the following stack trace:

msvcp140.dll!00007ffa1d488c34() Unknown
myapp.exe!std::_Mutex_base::lock() Line 52  C++
myapp.exe!std::unique_lock<std::mutex>::{ctor}(std::mutex &) Line 144   C++ 

We've analyzed all these reports and found that MSVC runtime DLLs in all these reports are loaded from C:\Windows\System32 folder, not from our app's folder. These runtime DLLs are way too older than the one we use (e.g. 14.28.29910.0 or 14.0.2415.1). And it seems they are not binary compatible with our app build.

Question: What are the possible reasons of why sometimes these system's DLLs are loaded instead of our app's provided ones?

In order to decrease our app's installer size and do not force the user to download MSVC runtime redistributable installer, we include all the MSVC runtime DLLs we need (and only them) into our installer using the following technique.

All was working fine during many years until now. Recently we've switched to use MSVC2022 and 14.42.34433.0 version of the runtime (pretty new one). Now, we're getting crash dumps from our users. Not too much (about 1 per 1000 users) with the following stack trace:

msvcp140.dll!00007ffa1d488c34() Unknown
myapp.exe!std::_Mutex_base::lock() Line 52  C++
myapp.exe!std::unique_lock<std::mutex>::{ctor}(std::mutex &) Line 144   C++ 

We've analyzed all these reports and found that MSVC runtime DLLs in all these reports are loaded from C:\Windows\System32 folder, not from our app's folder. These runtime DLLs are way too older than the one we use (e.g. 14.28.29910.0 or 14.0.2415.1). And it seems they are not binary compatible with our app build.

Question: What are the possible reasons of why sometimes these system's DLLs are loaded instead of our app's provided ones?

Share Improve this question edited Mar 6 at 12:28 Alexander Dyagilev asked Mar 6 at 10:14 Alexander DyagilevAlexander Dyagilev 1,3461 gold badge19 silver badges47 bronze badges 4
  • 2 Good question. I could not propose exact answer. However, without deep diving, I could propose couple reasons: 1) requested dll are not present in your app's folder (lost, damaged,copy-protected folder for dlls,copied to another folder, etc..); 2) your app does load dlls from a folder different from your app's folder (folder apps path is damaged or something else). Possible, there are some means that affect dll loading order, or reqiures dll registering. Sorry for superficial answer. – Michael Ermakov Commented Mar 11 at 19:21
  • Could it be that the users where this happens have another application already running that actually uses the problematic ancient System32 DLL? – Martin Brown Commented Mar 17 at 12:56
  • Are you sure that the version in the manifest matches the version of the DLLs you've included? – Ali Khakbaz Commented Mar 17 at 17:55
  • This might be off-topic, but do you have to add your app's installation directory to the env PATH? – SoftwareDveloper Commented Mar 17 at 20:42
Add a comment  | 

2 Answers 2

Reset to default 1

The culprit is Mozilla Firefox web browser.

User downloads and launches distributive using this web browser -> installer installs and launch our app -> app is loaded with C++ runtime installed in system instead of the one we provide.

This is not reproducible with other web browsers.

So by default, Windows will follow a specific search order for location DLLs when your app starts:

  1. The directory containing the executable

  2. The systems32 directory

BUT, certain issues can cause it to skip the app directory and go to the system 32 directory.

  1. If your app's folder doesn't contain ALL the necessary MSVC runtime dlls, it will go to the system32, so you could be missing 1 or more dependencies but have the other X dlls and it will still go to system32

  2. The version doesn't match exactly

    1. If you have an embedded manifest it will attempt to match EXACTLY on the version I.E. in your case 14.42.34433.0

    2. If you don't have a manifest it will attempt to do general match, usually major versions are compatible so any version 14 higher or lower will generally work, though not guaranteed. Those lesser versions usually have specific bug fixes in them, which may be why you are seeing issues in only a subset of users

So IN GENERAL - no manifest or incorrect version in manifest means default behavior, which means it will just use the system32 version which may be a version 14 but not the "right" version 14.

本文标签: windowsWhy are system39s MSVC runtime DLLs used instead of ours ones sometimesStack Overflow