我下载了"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位方位的绝对路径,这没有帮助。
我怎样才能让它工作?