title: VB6 API Declaration Path
body: <p>I have the following declaration in a Module:</p>
  
  <pre><code>Private Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As String, ByVal mode As String) As Long
  </code></pre>
  
  <p>The following code line in a function fails, with a 'File Not Found: ZLIB.DLL' error:</p>
  
  <pre><code>lGZFileHandle = gzopen(sPath, "rb")
  </code></pre>
  
  <p>I'm aware that ZLIB doesn't need to be registered.  My question is, where does ZLIB.DLL need to live in order for my code to work?  I also know that this code <em>is</em> working on another machine.  Currently I have ZLIB.DLL in the same folder as the application exe.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>To my relief, the code does work when compiled.  But does not work whilst running in the IDE (it does on a different machine).  I still have ZLIB.DLL in the application folder.
  This means that the application path must be being checked for loading the DLL.</p>
  
  <p>To get around this I have tried:</p>
  
  <pre><code>Private Declare Function SetDllDirectory Lib "Kernel32" Alias "SetDllDirectoryA" (ByVal path As String) As Long
  </code></pre>
  
  <p>and then in the function:</p>
  
  <pre><code>SetDllDirectory App.path
  </code></pre>
  
  <p>This seems to allow the DLL to load, but I then get a 'Bad DLL calling convention' error instead.  The plot thickens.</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>The answer seems to be here: <a href="http://www.zlib.net/DLL_FAQ.txt" rel="nofollow noreferrer">http://www.zlib.net/DLL_FAQ.txt</a>. It's a case of RTFM I suppose. 
  So, bizzarely whilst in the IDE, the <code>STD_CALL</code> convention is in force, but once compiled the C style calling convention suffices. It still doesn't explain why it works on a different machine in the IDE. Ho hum.</p>
  
  <p>Thanks all for pointing me in the right direction.</p>