4
votes

On my laptop, where I am developing the WPF application, everything works fine, debug and launch the .exe app.

My app uses a native DLL, for resolve the reference problem I add the DLL in bin/debug (release) folder. I access it using DllImport like this:

[DllImport("xptodll.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int LDA_About();

The problem is when I try to run the .exe app on another PC, when I need to access the DLL it crashes. I make a handle to log any unhandled exceptions and the following error appears:

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

The bin/debug directory has xptodll.dll, and app files: .exe, .application, .exe.config, .exe.manifest, .pdb.

Maybe this is important, the xptodll.dll interacts with hardware, but why wouldn´t it have the same behaviour on both machines?

2
Are you compiling for x86 or x64? Is the OS bitness different between your laptop and the other PC? 64-bit exes cannot load 32-bit DLLs, and hardware interface DLLs typically aren't managed and written with AnyCPU and such.Sean Hanley
You cannot get the debug build of your DLL going on another machine, it won't have the debug version of the CRT available. Only deploy the Release build. And deploy the runtime DLLs it needs: microsoft.com/download/en/details.aspx?id=5555Hans Passant
and I have to install vc++ 2010 in each machine i install the app ? why VisualStudio dont catch dependency of that when a create a setup project ? only detects .net dependency ....Cristóvão Macedo

2 Answers

15
votes

There is probably some further dependency that is failing. My guess is that xptodll.dll itself has dependencies on other libraries that are missing on the failing machine. The documentation of xptodll.dll should explain what dependencies are needed. If the documentation does not make it obvious what is missing, you can diagnose the problem yourself using Dependency Walker.

3
votes

Another issue might be (beside all this "put the DLL in the correct location") that if the DLL was created with Visual Studio, eg. Visual Studio 2012, also the VCRedistributable for 64 bit must be installed (vcredist_x64.exe), which is profided by Visual Studio.