I downloaded zlib and compiled a library of both 32-bit Windows and 64-bit Windows dll. Now I have zlibwapi.dll
and zlibwapi64.dll
.
The DLL files are copied to my application folder and are listed as follows:
[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 );
At runtime, I check if I am 32-bit or 64-bit, and call the appropriate version.
This works fine if I'm 32-bit, but the 64-bit version gives
Unable to load DLL "zlibwapi64.dll": module not found. (HRESULT exception: 0x8007007E)
I found a lot of similar questions on the Internet, and the alleged reason was that the library depends on some other libraries, and these libraries cannot be found.
This is not like the case:
- zlibwapi64.dll depends only on Kernel32.dll and MSVCR90.dll. I have a VS2008 C ++ runtime, both 32 and 64 bit.
- When I try to download zlibwapi64.dll from an unmanaged C ++ application, it does not load any problems. This is C # that does not load it.
I tried to set the absolute path to the 64-bit dll, this will not help.
How can I make it work?