-1

I have a WinForms application which has a C++ library called DeviceAccess. The C# libraries are targeting the .NET Framework 4.5.1 (x86), and my C++ library is targeting Windows SDK Version 8.1 and Platform Toolset Visual Studio 2017 (v141) and Win32. I am building the application on my Windows 10 machine and trying to run through virtual machines of Windows 8.1 and Windows 7.

enter image description here

I've already set those two defines inside targetver.h, which looks like:

#pragma once

#define WINVER 0x0601
#define _WIN32_WINNT 0x0601 

#include <SDKDDKVer.h>

But, still when I open the application through my virtual machine of Windows 8.1 or Windows 7, I get the following error:

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

I have the .dll at the same folder as the application.

Someone have any idea why I cannot load the C++ library, please?

EDIT: I run the Process Monitor and filtered the missing DLL, as shown below:

enter image description here

I feel like the missing VCRUNTIME140.dll might be the issue?

EDIT2:

From Dependecy Walker I got those error when loading that DLL:

enter image description here

Renato Pereira
  • 834
  • 2
  • 9
  • 22
  • "or one of its dependencies" - can you verify that all of the dependencies are available? Back in the day we used to use Dependency Walker for that, here's [a suggestion of a modern replacement](https://stackoverflow.com/q/33604738/243245). You could try running regsvr32 on the dll which would also error if the dependencies were missing. (If not, it will error if your DLL isn't COM.) Or you could use Sysinternals Process Monitor to watch the load and see what files it's trying to access and failing, but that generates a lot of logs that take some effort to wade through. – Rup Jul 10 '18 at 17:05
  • I tried to run regsvr32 on the dll and it gave me this error: "The module "PATH\DeviceAccess.dll" failed to load. Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent .DLL files. The specified module could not be found." – Renato Pereira Jul 10 '18 at 17:13
  • Hi @rup, I've updated my question with the process monitor analysis – Renato Pereira Jul 10 '18 at 17:37
  • Great. It's difficult to tell from that though which ones of those it did go on to find, and which it never managed to find. But if it is VCRUNTIME140 then you probably want the VS2015 (which I think is version 14.0) vcredist.exe from here: https://support.microsoft.com/en-gb/help/2977003/the-latest-supported-visual-c-downloads – Rup Jul 10 '18 at 17:43
  • Dependency Walker doesn't understand SxS loading in modern windows. Yes, that probably is the issue but I don't know if the dependency walker output is reliable anymore. – Rup Jul 10 '18 at 17:45
  • Hmm, why wouldn't work with VS2017? I can run fine on my Windows 10 machine. – Renato Pereira Jul 10 '18 at 17:46
  • Yes, you need to deploy vcruntime140.dll and msvcp140.dll as well. Same directory as the EXE is a good place for them. – Hans Passant Jul 10 '18 at 19:41
  • how can I deploy them? Is there any command I should use? – Renato Pereira Jul 10 '18 at 21:00

1 Answers1

3

So I fix my own problem. I had a WiX setup installer with the following commands:

<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>

Which deploys the msvcp140.dll and vcruntime140.dll. However I was still missing the api dlls of the Universal CRT. So I use this 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\10\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).

Thus, after I copied all the binaries files from x86 to my application folder, I was able to run it on the Windows 8.1 VM.

EDIT: For those who are curious about how to deploy the Universal CRT dlls in the WiX setup installer, I've followed this.

Renato Pereira
  • 834
  • 2
  • 9
  • 22