title: C++ DLL program called from VB6 cannot be found
body: <p>We compiled a C++ program as DLL and want to use it from VB6. The program has subroutines like </p>
  
  <pre><code>int __stdcall setup(int exposure_time, double shutter, double gain, int numImages) {
  ....
  }
  
  int __stdcall test() {
    return 8;
  }
  </code></pre>
  
  <p>And the Def file is defined as:</p>
  
  <pre><code>LIBRARY
  EXPORTS
     setup=setup
     test=test
  </code></pre>
  
  <p>And we are declaring them in VB6 like this:</p>
  
  <pre><code>Public Declare Function setup Lib "C:\MyDll.dll" () As Long
  
  Public Declare Function test Lib "C:\MyDll.dll" () As Long
  </code></pre>
  
  <p>And trying to access then in a form:</p>
  
  <pre><code>Private Sub Form_Load()
  
       Debug.Print (test())
  
  End Sub
  </code></pre>
  
  <p>But we are getting "File not found" in VB, when the execution hits to very first function call! The MyDll.dll program is in the declared location and it is not to be registered. What is missing to declare? </p>
  
  <p>Hello Bathsheba,</p>
  
  <p>I followed your suggestions but the VB program still could not find the dll.</p>
  
  <p>Declarations in VB:</p>
  
  <pre><code> Public Declare Function setup Lib "C:\Math\FlyCapture2\bin\PGLCTrigger.dll" ( _
       ByVal exposure_time As Long, _
       ByVal shutter As Double, _
       ByVal gain As Double, _
       ByVal numImages As Long) As Long
  
   Public Declare Function test Lib "C:\Math\FlyCapture2\bin\PGLCTrigger.dll" () As Long
  </code></pre>
  
  <p>Def File:</p>
  
  <pre><code> LIBRARY
   EXPORTS
      setup=@1
      test=@2
  </code></pre>
  
  <p>C++ program:</p>
  
  <pre><code> __declspec(dllexport) int __stdcall setup(int exposure_time, double shutter, double gain,  int numImages) {
   ....
  }
  
   __declspec(dllexport) int __stdcall test() {
      return 8;
  }
  </code></pre>
  
  <p>And the VB calling program:</p>
  
  <pre><code> Private Sub Form_Load()
  
        setup 12, 24#, 1#, 10
        test
  
   End Sub
  </code></pre>
  
  <p>As soon as the execution hits the setup line in the program above, the "dll not found" error comes. </p>
  
  <p>I defined the following in a .def file as suggested by <a href="https://stackoverflow.com/questions/847396/compile-a-dll-in-c-c-then-call-it-from-another-program?rq=1">Compile a DLL in C/C++, then call it from another program</a>:</p>
  
  <pre><code> //DLL Export-Import definitions
  #ifdef BUILD_DLL
  #define EXPORT __declspec(dllexport)
  #else
  #define EXPORT __declspec(dllimport)
  #endif
  </code></pre>
  
  <p>So that I can reference the functions in the DLL as</p>
  
  <pre><code>EXPORT int __stdcall setup(int exposure_time, double shutter, double gain, int numImages)
  </code></pre>
  
  <p>But VS2010 produces an error message for the import. </p>
  
  <p>So I am stuck. Any further help will be appreciated a lot. Thank you.</p>