LoadLibrary project.dll failed. The specified module could not be found

亡梦爱人 提交于 2019-12-22 05:05:25

问题


When I try to register the 32 bit version of my C++ / ATL project with

regsvr32 project.dll

i'm getting this error:

LoadLibrary("project.dll") failed - The specified module could not be found

project.dll is my dll built using ATL on Visual Studio 10.

The 64 bit version registered fine.

What am I missing?


回答1:


I have observed this exact same error, but the solution was not installing the redistributable. All the dependent DLLs were present on the system1 according to depends.exe.

In my case, the icon of KERNEL32.DLL was slightly red tinted. Depends.exe did not offer much explanation, but digging around revealed that one of the imported functions were missing from the DLL on the system. To see the imported functions, select the dependent DLL in the treeview and look for the import on the right panel. Order by the PI column to see the red icons of missing imports.

In my case, the missing function was a function that did not exist on my sad target operating system, Windows XP. Since my program did not directly depend on this function, I was able to get away with #defineing the following in my project:

#define WINVER 0x0501
#define _WIN32_WINNT 0x0501

Compiling with these macros made it so the function in question was not declared in the headers, and consequently not imported at load-time. Now I was able to use regsvr32. This of course is a very specific (and lucky) case. I did not depend on that import or any other newer APIs, so I could get away with retargeting the project. Were it not a system DLL, I would have needed to find a newer version which could easily lead to a need to update a whole sub-tree of the dependency graph. Or even worse, if I depended on the missing imports, some serious refactoring would be needed.

To sum it up, this error message2 can be caused by the following issues:

  1. The DLL file was not found or could not be read. Check the command line.
  2. Some dependent DLLs were not found or could not be read.
  3. Some imports are missing from some dependent DLLs. If these are system DLLs, you are likely targeting a wrong version of Windows. If these are non-system DLLs, you need to install newer versions of them and all their dependencies.

1.: Apart from IESHIMS.DLL and WER.DLL which is apparently a bug in this old tool.
2.: Or really, any problems in loading the DLLs on a particular system




回答2:


The error description is misleading in this case. The system finds your DLL (project.dll) but one (or more) dependency of your DLL might be missing.




回答3:


I just installed

Microsoft Visual C++ 2010 Redistributable Package 

and now I can install the dll.

Although this works, I'm not too happy with this, because I don't want to have to install this package on a client in order for my dll to work by them.



来源:https://stackoverflow.com/questions/11717312/loadlibrary-project-dll-failed-the-specified-module-could-not-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!