0

I'm building a Visual C++ executable. The Release output folder contains the EXE and the dependent DLLs. However, if I rename one of the DLLs and run the EXE, the EXE will fail load with exit code -1073741515 (0xC0000135) which means STATUS_DLL_NOT_FOUND. This is expected, however the cause for the load failure is non-transparent to the user since the EXE will just silently "crash" and not generate a helpful error message such as The DLL xyz.dll was missing. Some end users might genuinely miss a DLL or a Visual C++ Redistributable installation which makes debugging the problem hard.

Is there any way to tell the Windows application loader to provide an error message pop-up with diagnostics as to why the EXE failed to run properly? I have full control over the Visual Studio project settings and the source code. My project is configured as a command line application though if that could be the cause for no graphical loading failure feedback.

Here is a related question for a similar issue when running an EXE from Java.

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • Related: https://stackoverflow.com/questions/18366433/createprocess-status-dll-not-found-which-dll – Vlad Feinstein Apr 28 '21 at 17:14
  • Step #1: Use delay-loading. Step #2: Install a delay-load handler/hook. Unfortunately this won't work for the C runtime library itself since the compiler support for delay-load assumes the C runtime is available. – Ben Voigt Apr 28 '21 at 17:16
  • Approach #2: Move all your application code that uses the C runtime to a DLL. Turn the EXE into a tiny shim that manually loads your application logic DLL, handling loading and error checking using only the Win32 API and no standard C calls. Some versions of the CRT can't be manually loaded, but you could always manually load a "probe" DLL that takes care to depend on the CRT and nothing else. – Ben Voigt Apr 28 '21 at 17:17
  • 1
    [Linker support for delay-loaded DLLs](https://learn.microsoft.com/en-us/cpp/build/reference/linker-support-for-delay-loaded-dlls). That allows your application to display additional information. The system won't show anything more useful than the exit code. – IInspectable Apr 28 '21 at 17:18
  • 4
    *"Some end users might genuinely miss a `DLL` or a `Visual C++ Redistributable` installation"* - That sounds odd. If your code relies on the Visual C++ Redistributable, then your installer is required to install it. You cannot just ship your code and hope for dependencies to be there. – IInspectable Apr 28 '21 at 17:25
  • Thanks guys, I decided to implement delay loading and a delay load failure hook. That works quite well. :) Also I can statically link the runtime to avoid this problem. I'm not making an installer but I'm distributing the `EXE` with `DLL`s manually as part of another application written in `Java`. – BullyWiiPlaza Apr 28 '21 at 21:06

0 Answers0