LoadLibrary 失败并出现模块未找到错误 - 可能存在依赖性问题
我一直在尝试使用 C++ 加载 32 位 dll(从 32 位应用程序,在 Windows 7 64 位上)。 LoadLibrary 返回 NULL,GetLastError 返回 126,表示“找不到指定的模块”。
我将完整地址传递给 LoadLibrary 函数。我在 Dependency Walker 中打开了 dll,它说 GPSVC.dll 是缺少的依赖项。
从我完成的谷歌搜索来看,Dependency Walker 似乎经常错误地将 GPSVC.dll 显示为缺少的依赖项,并且没有它的 32 位版本,所以我认为这不是真正的问题。
我过去没有对 dll 做过太多的欺骗,所以希望这是一个相对简单的问题,我可以从中学习。
预先感谢您的任何帮助!
I have been trying to load a 32-bit dll using C++ (from a 32-bit application, on windows 7 64-bit). LoadLibrary returns NULL, and GetLastError returns 126 for "The specified module could not be found."
I am passing in the complete address to the LoadLibrary function. I opened the dll in Dependency Walker, which said GPSVC.dll was a missing dependency.
From the googling I've done, it looks like Dependency Walker often falsely shows this GPSVC.dll as a missing dependency, and there is no 32-bit version of the it, so I don't think that that's the actual problem.
I haven't done too much finagling with dlls in the past, so hopefully it's a relatively simple problem that I can learn from.
Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我解决了我的问题,不幸的是这是一个相当明显的解决方案。我将包含 dll 的目录添加到 PATH 变量中。显然 dll 不会在自己的目录中查找依赖项。
Well I solved my problem, and unfortunately it's a fairly obvious solution. I added the directory that contained my dll to the PATH variable. Apparently dlls don't look in their own directory for their dependencies.
你能调试到另一个dll的DllMain吗?如果是的话,你可以直接在调试器中检查。使用 Windbg,您可以中断模块加载,这样您就可以单步执行所发生的事情。你直接链接到dll的lib吗?如果没有,您可以尝试这样做以检查操作系统将向您显示什么错误消息。如果是 0xC0000142,则 DllMain 确实返回 false。如果是 0xC0000022,则可执行文件或依赖的 dll 之一没有执行权限。您的代码 126 只是找不到模块,这似乎说明了整个故事。您可以手动将 PATH 变量设置为丢失 dll 所在的目录。
您是否将 dll 部署到其他机器上?如果是,则可能是您正在链接
普通机器上未安装的调试 C-Runtime。
你的,
阿洛伊斯·克劳斯
Can you debug into the DllMain of the other dll? If yes you could check directly in the debugger. With Windbg you can break on module load so you can single step what happens. Do you link directly against the lib of the dll? If not you could try to do so to check what error message the OS will show you. If it is 0xC0000142 then DllMain did return false. If it is 0xC0000022 then the executable or one of the dependant dlls do not have execute rights. You code 126 is simply Module not found which seems to tell the whole story. You could set the PATH variable to the directory by hand to the location of the missing dll.
Do you deploy the dll to some other machine? If yes it could be that you are linking against
the debug C-Runtime which is not installed on normal machines.
Yours,
Alois Kraus