0

In my C# Wpf project, I need some funtion from C++. So I make my own C++ DLL project named LibC. And the Wpf app can run normally in my computer. But on the tester's computer, the log says:

Unable to load DLL 'LibC.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

And I checked that the DLL file LibC.dll is there. By checking this post: Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

Anthony Hayward's answer inspires me. So I run below dumpbin command and find that my dll rely on those 4 Window's dll. And on the tester's computer, two are missing: vcruntime140d.dll and ucrtbased.dll. While on my computer, all the four dlls can be found. So I copied the missing two dlls to the tester's computer, put them together with my LibC.dll, then the app works well now.

My question is how to solve this kind of problem in a better way? As I said, I copy the missing dll files manually to the tester's computer.

Another options is to put the two dlls into my project and release them together with my project files, including the exe file and LibC.dll.

Is it possible to statically link the two missing dll into my LibC.dll? Or any other advise?

"c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\vc\Tools\MSVC\14.29.30133\bin\Hostx64\x64\dumpbin.exe" /DEPENDENTS libc.dll
Microsoft (R) COFF/PE Dumper Version 14.29.30143.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file libc.dll

File Type: DLL

  Image has the following dependencies:

    KERNEL32.dll
    USER32.dll
    VCRUNTIME140D.dll
    ucrtbased.dll

  Summary

        1000 .00cfg
        1000 .data
        2000 .idata
        1000 .msvcjmc
        3000 .pdata
        4000 .rdata
        1000 .reloc
        1000 .rsrc
        A000 .text
       10000 .textbss
Tom Xue
  • 3,169
  • 7
  • 40
  • 77
  • Put the dll in the same folder as the executable. Do that by creating an installer that installs your application + required dlls. – drescherjm Jun 08 '22 at 12:32
  • 1
    yes, it is possible to compile with runtime statically you need to set it in C++ project – Selvin Jun 08 '22 at 12:33
  • 2
    `VCRUNTIME140D.dll` and `ucrtbased.dll` may be a problem and is a little confusing to me as this is part of the debug runtime. You are not supposed to run debug executables on machines that don't have Visual Studio installed. This is why the debug runtime is not in the redistributable. – drescherjm Jun 08 '22 at 12:34
  • you can link statically debug or release verision ... there is no differeneces .. with MT/MTd MD/MDd flags ... there should be an option in C++ project properties – Selvin Jun 08 '22 at 12:35
  • You must build and deploy the Release flavor of this DLL. The debug runtime is not distributable and only suitable to get the bugs out of the code. It alters the behavior of the C/C++ code so cannot be relied on to reliably test the way the code is going to run on the user's machine. – Hans Passant Jun 08 '22 at 13:00
  • @drescherjm You find the reason of my issue. Those two DLL files are for debug version and our tester's computer doesn't install Visual Studio, so the app cannot find those DLL files and cause the issue. Thank you and all the other guys for your kindly help! – Tom Xue Jun 09 '22 at 16:38

1 Answers1

0

Your users will need to install the visual c++ runtime. The typical way to do this would be with an installer that does this silently. As far as I know they cannot be compiled into your program, and that the license prohibit distribution of lose dlls outside the redistribution package.

Note that you may need to update this package if you update the Visual studio version used to compile your dll.

Also note that you need to deploy the release build of your application, since the debug version of the dlls is only distributed as part of visual studio.

At last, that pure .Net code does not have these kinds of problems, so if you have c++ code it might be better to just rewrite it in c#. If you want to access some third party dll it might be better to use P/Invoke directly to that dll.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • 1
    "Also note that you need to deploy the release build of your application, since the debug version of the dlls is only distributed as part of visual studio." --- this is the root cause of my issue, thank you! – Tom Xue Jun 09 '22 at 16:42