无法在 Windows 7 和 8.1 上使用 C++ 库 运行 Winforms 应用程序

Cannot run Winforms application with C++ library on Windows 7 and 8.1

我有一个 WinForms 应用程序,它有一个名为 DeviceAccess 的 C++ 库。 C# 库的目标是 .NET Framework 4.5.1 (x86),我的 C++ 库的目标是 Windows SDK Version 8.1 和 Platform Toolset Visual Studio 2017 (v141) 和 Win32。我正在我的 Windows 10 机器上构建应用程序并尝试 运行 通过 Windows 8.1 和 Windows 7.

的虚拟机

我已经在 targetver.h 中设置了这两个定义,看起来像:

#pragma once

#define WINVER 0x0601
#define _WIN32_WINNT 0x0601 

#include <SDKDDKVer.h>

但是,当我通过 Windows 8.1 或 Windows 7 的虚拟机打开应用程序时,仍然出现以下错误:

Could not load file or assembly '...DeviceAccess.dll' or one of its dependencies. The specified module could no be found.

我的 .dll 与应用程序位于同一文件夹中。

有人知道为什么我无法加载 C++ 库吗?

编辑: 我运行 Process Monitor过滤掉了丢失的DLL,如下图:

我觉得缺少 VCRUNTIME140.dll 可能是问题所在?

编辑 2:

从 Dependecy Walker 我在加载那个 DLL 时遇到了这些错误:

所以我解决了我自己的问题。 我有一个带有以下命令的 WiX 安装程序:

<DirectoryRef Id="TARGETDIR">
    <Merge Id="VCRedist" SourceFile="..\MergeModules\Microsoft_VC140_CRT_x86.msm" DiskId="1" Language="0"/>
    <Merge Id="VCRedist2" SourceFile="..\MergeModules\Microsoft_VC140_CXXAMP_x86.msm" DiskId="1" Language="0"/>
</DirectoryRef>

<Feature Id="VCRedist" Title="Visual C++ 14.0 Runtime" AllowAdvertise="no" Display="hidden" Level="1">
    <MergeRef Id="VCRedist"/>
    <MergeRef Id="VCRedist2"/>
</Feature>

部署 msvcp140.dll 和 vcruntime140.dll。但是我仍然缺少通用 CRT 的 api dll。所以我用这个 approach:

Updated September 11, 2015: App-local deployment of the Universal CRT is supported. To obtain the binaries for app-local deployment, install the Windows Software Development Kit (SDK) for Windows 10. The binaries will be installed to C:\Program Files (x86)\Windows Kits\Redist\ucrt. You will need to copy all of the DLLs with your app (note that the set of DLLs are necessary is different on different versions of Windows, so you must include all of the DLLs in order for your program to run on all supported versions of Windows).

因此,在我将所有二进制文件从 x86 复制到我的应用程序文件夹后,我能够 运行 它在 Windows 8.1 VM 上。

编辑: 对于那些对如何在 WiX 安装程序中部署通用 CRT dll 感到好奇的人,我已经关注了 this.