title: DllNotFoundException with HRESULT 0x8007007E when loading 64-bit dll
body: <p>I downloaded <a href="http://zlib.net/" rel="noreferrer">zlib</a> and compiled the library as both Windows 32-bit and Windows 64-bit dll. I now have <code>zlibwapi.dll</code> and <code>zlibwapi64.dll</code>.</p>
  
  <p>The dlls are copied into my application folder and are referenced as follows:</p>
  
  <pre><code>[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
  );
  </code></pre>
  
  <p>At runtime I check whether I'm 32-bit or 64-bit, and call appropriate version.</p>
  
  <p>This works fine if I'm 32-bit, but the 64-bit version gives</p>
  
  <blockquote>
    <p>Cannot load DLL "zlibwapi64.dll": Module not found. (HRESULT exception: 0x8007007E)</p>
  </blockquote>
  
  <p>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.<br>
  This does not seem to the case:</p>
  
  <ul>
  <li>zlibwapi64.dll only depends on Kernel32.dll and MSVCR90.dll. I do have VS2008 C++ runtimes installed, both 32 and 64 bit.</li>
  <li>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.</li>
  </ul>
  
  <p>I have tried setting absolute path to the 64-bit dll, it does not help.</p>
  
  <p>How do I make it work?</p>