views:

38

answers:

4

Hi,

I have a project A linked to a project B. B is compiled into a .dll while A is the main program and compiled into a .exe

The compiling of the projects is done without any issues, but when I run the program, I get a pop-up window saying "This application has failed to start because B.dll was not found. Re-installing the application may solve the problem."

I have done several cleanings, tried to move the dll, but that won't work.

I am using visual Studio 9.0 btw

+1  A: 

The dll needs to be on the path or in the same directory as executable A.

Then there is the possibility that dll B is somehow not a valid dll

Martin Beckett
Moving to the .exe directory works, thanks! But how do you specify to be on the path of executable A?
ChRtS
"The path" is a global setting (environment variable `%PATH%`), not particular to executable A.
MSalters
Sorry poorly phrased. On the global path OR in the specific directory of the executable
Martin Beckett
A: 

Do the changes here to include you library paths. Tools -> Options -> Projects and Solutions -> VC++ Directories

Right click your project and click Properties. In Configuration Properties/Linker mention your dependencies(dll files) in Additional dependencies.

DumbCoder
+2  A: 

When Windows loads an EXE, it will check what DLL's are needed, directly or indirectly. In your case, A.EXE will need B.dll. When Windows has determined that list, it will use this procedure to locate the DLLs:

  • The directory where the executable is stored [1]
  • The current directory, as set by CreateProcess()
  • The Windows system directory (holds most of the Windows DLLs such as USER32.DLL)
  • The Windows directory (for legacy reasons, mostly)
  • The directories from the PATH variable (also for legacy reasons)

[1] Symbolic links can cause an executable to have multiple paths. To be precise here, it's the path of the executable that was passed to CreateProcess.

MSalters
Is current directory still searched for DLL-s in current Windows versions? Because it used to be a pretty big security hole.
Tomek Szpakowicz
But the alternative is to put your application specific DLLs in windows\system !
Martin Beckett
@Martin: why and how is that an alternative to the current directory?
MSalters
+1  A: 

As already mentioned, Dll should be in the same directory as .exe, or available throug PATH environment variable. Dll can be found also if it is in the current directory, Windows or System32 directory.

Having two diffetent projects, you can add post-build step to Dll project, copying Dll to .exe directory. It is convenient to keep Dll end exe in the same solution. By default, output directory is $(SolutionDir)$(ConfigurationName), this means, all .exe and .dll files in the solution are written to the same directory. In this case, dll loading problem is solved automatically.

Alex Farber