English 中文(简体)
装载 64 位 dl 时带有 HResult 0x8007007E 的无例外
原标题:DllNotFoundException with HRESULT 0x8007007E when loading 64-bit dll

我下载了"http://zlib.net/" rel="noreferrer">zlib ,并将图书馆编译为Windows 32-bit和Windows 64-bit dll。我现在有zlibwapi.dll zlibwapi64.dll

将数据夹复制到我的应用程序文件夹中,并注明如下:

[DllImport(@"zlibwapi.dll",   EntryPoint = "uncompress", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = false)]
private static extern int uncompress32(
    IntPtr dest,
    ref uint destLen,
    [In(), MarshalAs(UnmanagedType.LPArray)] byte[] source,
    uint sourceLen
);

[DllImport(@"zlibwapi64.dll", EntryPoint = "uncompress", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = false)]
private static extern int uncompress64(
    IntPtr dest,
    ref uint destLen,
    [In(), MarshalAs(UnmanagedType.LPArray)] byte[] source,
    uint sourceLen
);

运行时,我检查我是32比特还是64比特, 并调用适当的版本。

如果我是 32 位,但64 位版本给出了

无法装入 DLL “ zlibwapi64. dll ” : 找不到模块 。 (HResult 例外: 0x8007007E)

I ve found many similar questions on the Internet, and the suggested reason was that the library depends on some other libraries, and it is those libraries that may not be found.
This does not seem to the case:

  • zlibwapi64.dll only depends on Kernel32.dll and MSVCR90.dll. I do have VS2008 C++ runtimes installed, both 32 and 64 bit.
  • When I try to load zlibwapi64.dll from a non-managed C++ application, it loads no problem. It is C# that fails to load it.

我尝试了设定64位方位的绝对路径,这没有帮助。

我怎样才能让它工作?

最佳回答

这是一个相当基本的“ 找不到文件” 错误, 不幸的是, 它没有明确地告诉你它找不到什么 DLL 。 您已经知道依赖 DLL 的问题。 请注意, 您可以用 / MT 编译代码来避免对 msvcr90. dll 的令人讨厌的依赖 。

您需要调试问题, 这需要了解它在哪里查找 DLLs 。 一个好工具是 < a href=" http://technet. microsoft.com/ en- us/sysinternationals/bb896645.aspx> > Sys Internals Procmon wirk , 它可以显示您的程序正在查找文件的确切位置 。 您应该看到它为 DLLS 探测, 通过 PATH 目录搜索并且找不到文件 。

不幸的是, ProcMon有点闲聊, 并且习惯于将您淹没在数据中。 一个更专门的工具是 GFlags.exe, 这是 Windows 软件包调试工具中可用的工具 。 这些天包括 Windows SDK 。 保存在 c: program 文件中 。 用于 windowsgflags 的 X86 调试工具 。 安装后您可以打开“ 显示装载器抓抓抓” 选项。 在较晚的 Windows 版本中, 该版本告诉 Windows 装入器在搜索 DLL 时生成调试信件。 当您启用未管理的调试功能时, 它们会出现在 输出窗口 。

先试试ProcMon,走容易得多

当然,也应该考虑纯粹的管理型解决方案,这样你就不会和这些安装问题作斗争。 最好的办法就是DotNetZip和SharpZipLib,他们第一次打谷歌。

问题回答

检查依赖性的另一个好工具是依赖性行走器(依赖性),它静态地看文件,比使用程序监视器容易得多。

http://www.depidentencywalker.com/" rel="no follow" >http://www.depidentencywalker.com/





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签