What to do with "This application has failed to start because myproject.dll was not found." error
I have a project A linked to a project B. B is compiled into a .dll while A is the m开发者_如何学Cain 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
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.
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
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.
精彩评论