VB.NET 无法加载 DLL 找不到指定的模块。当 dllimport
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19030099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET Unable to load DLL The specified module could not be found. when dllimport
提问by william pagnon
I'm adding VC++ lib in my VB .Net program using for instance:
我在我的 VB .Net 程序中添加 VC++ lib 使用例如:
<DllImport("KMpeg4.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Shared Function KOpenInterface() As System.IntPtr
End Function
I've got at runtime the error:
我在运行时遇到错误:
Unable to load DLL 'KMpeg4.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
无法加载 DLL 'KMpeg4.dll':找不到指定的模块。(来自 HRESULT 的异常:0x8007007E)
I've put this lib everywhere, including system32, still no luck, which mean it missing dependent lib of KMpeg4.dll.
我把这个库放在任何地方,包括system32,仍然没有运气,这意味着它缺少KMpeg4.dll.
So I've run Dependency walker which gave me the missing lib:
所以我运行了 Dependency walker,它给了我丢失的库:
API-MS-WIN-CORE-COM-L1-1-0.DLL API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL API-MS-WIN-CORE-WINRT-L1-1-0.DLL API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL DCOMP.DLL GPSVC.DLL IESHIMS.DLL
and the bad lnking function:
和坏链接功能:
c:\windows\system32\API-MS-WIN-CORE-THREADPOOL-L1-1-0.DLL c:\windows\system32\OLE32.DLL c:\windows\system32\DWMAPI.DLL c:\windows\system32\IEFRAME.DLL c:\windows\system32\IMM32.DLL c:\windows\system32\MFPLAT.DLL c:\windows\system32\NDFAPI.DLL c:\windows\system32\USERENV.DLL c:\windows\system32\UXTHEME.DLL
dependency walker gives the following errors:
依赖行走器给出以下错误:
Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
警告:至少找不到一个延迟加载依赖模块。警告:由于延迟加载相关模块中缺少导出功能,至少有一个模块具有未解析的导入。
I've I have already install Microsoft VC++ 2005,2008,2010 x86 and x64 and .Net framework 4.
我已经安装了 Microsoft VC++ 2005、2008、2010 x86 和 x64 以及 .Net framework 4。
As well I try to see if the KMpeg4.dllpopup using sysinternal process monitor, but it does not load KMpeg4.dllbefor the program get the error exception
同样,我尝试查看KMpeg4.dll使用 sysinternal 进程监视器的弹出窗口,但它不会KMpeg4.dll在程序获取错误异常之前加载
Any ideas from which package those lib could come from?
这些库可能来自哪个包的任何想法?
or alternatively, how to get around this problem?
或者,如何解决这个问题?
采纳答案by Hans Passant
Dependency Walker is not useful to diagnose this problem, DLLs like this are found only at runtime. Copying into system32 is usually the sledge-hammer solution. Except on a 64-bit version of Windows with your project's Platform target set to x86, very likely in this case since this is surely a 32-bit DLL, you then need to hammer it into c:\windows\syswow64.
Dependency Walker 对诊断这个问题没有用处,像这样的 DLL 只能在运行时找到。复制到 system32 通常是大锤解决方案。除了在项目的平台目标设置为 x86 的 64 位版本的 Windows 上,很可能在这种情况下,因为这肯定是一个 32 位 DLL,然后您需要将其敲入 c:\windows\syswow64。
But don't do that, you just need to make sure that the DLL is present in the same directory as your project's EXE. Best way to do so:
但是不要那样做,您只需要确保 DLL 与项目的 EXE 位于同一目录中。最好的方法是:
- Right-click your EXE project, Add + Existing item
- Navigate to your copy of KMpeg4.dll and select it
- Select the added item, set the Copy to Output Directory property to "Copy if newer"
- 右键单击您的 EXE 项目,添加 + 现有项目
- 导航到您的 KMpeg4.dll 副本并选择它
- 选择添加的项目,将复制到输出目录属性设置为“如果更新则复制”
Rebuild and you'll now have a copy of the DLL in the right place. Don't forget to deploy it along with your project's executables and don't forget the runtime support DLL that it might need on your user's machine.
重新构建,您现在将在正确的位置拥有 DLL 的副本。不要忘记将它与您的项目的可执行文件一起部署,不要忘记它在您的用户机器上可能需要的运行时支持 DLL。

