4

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

OS: Windows 7

I have two stations, Visual Studio 2012, using .net 4.0; the other don't have VS installed On the first station with VS2012 I have a C# solution with a C++ project imported. I'm using:

    [DllImport("x.dll", CallingConvention = CallingConvention.Cdecl)]
    [return: MarshalAs(UnmanagedType.I4)]

On this station is working.

But when I moved on the other station (that don't have VS installed) it appear that error. If I install VS, it's working.

What are some possible reasons for this problem to occur? Any ideas on what I could be missing or how I could debug this problem?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Ice
  • 193
  • 1
  • 2
  • 13

2 Answers2

10

The most likely reason is that the machine which does not have Visual Studio installed is missing the C++ runtime that is needed by your unmanaged DLL. Install the appropriate C++ runtime from the downloadable redistributable.

Do make sure that your unmanaged DLL is linked against the release runtime and not the debug runtime. The latter cannot be redistributed.

You can debug unmanaged DLL dependency issues using tools like Dependency Walker, Process Monitor etc.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I installed vcredist_x86_vs2012.exe. The same error. I will try with Dependency Walker – Ice Jan 15 '14 at 13:15
  • Then use Dependency Walker to debug the missing dependency. I would not be at all surprised if you had linked the DLL to the debug runtime. – David Heffernan Jan 15 '14 at 13:16
  • I used Dependency Walker to debug the missing dependency and I observed that are missing these dlls: mfc110.dll, mfc111d.dll, msvcp110.dl, msvcp110d.dll, msvcr110.dll, msvcr110d.dll. Solution: I added these dlls in Release folder, now the program is working. I don't know why it can not see these dlls from SysWOW64. Do you have another solution? – Ice Jan 22 '14 at 14:43
  • You've linked to the debug runtime. You cannot redistribute that. Link against release runtime. Clearly you have dependency on mfc too. Need to resist that too. – David Heffernan Jan 22 '14 at 14:47
1

I had the same problem

  1. Use Dependency Walker to check the missing dependencies

  2. In my case, I was missing msvcp110d.dll and msvcr110d.dll

  3. I copied these two files from my dev PC to test PC's C:\Windows\SysWOW64 PC and worked!

  4. Also, you can add Visual Studio C++ 11.0 DebugCRT(x86) as a dependency in InstallShield to make it work

kakopappa
  • 5,023
  • 5
  • 54
  • 73