Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 - DLL cannot be found

Tags:

windows

dll

vb6

I'm trying to load a DLL in VB6 using the command

Private Declare Function myFuncLib "myDLL.dll" (ByVal file_name_in As String, _ ByVal file_name_out As String) As Long

But as soon as I run the program it pop-up a box with the text": "Run time error: 53 Cannot find: myDLL.dll"

The DLL is placed in the same directory of the project.

If I put myDLL.dll in the system32 folder it works, but I don't want to do it, I would like to place the dll in the same folder of the project.

Is there a way to solve this problem?

Thanks

like image 251
Beppe Avatar asked Mar 08 '11 15:03

Beppe


2 Answers

My psychic powers predict you are running from the VB6 IDE - because a built EXE would find DLLs in the app directory (the same directory as the exe).

  • When you run from the VB6 IDE, it will find DLLs from the app directory... but it considers the app directory to be the directory containing the VB6 IDE itself :(
  • One workaround is to change the current working directory to be the VBP directory before you try to use the DLL. E.g. Chdrive App.Path: Chdir App.Path (air code)
  • EDIT Following comment from Beppe. Another workaround you could try is, just on your development machine, put a copy of the DLL in the same directory where the VB6 IDE is installed. Probably C:\Program Files\Microsoft Visual Studio\VB98\ You can put the DLL with your built EXE on the user machines / production machines.
like image 187
MarkJ Avatar answered Sep 30 '22 06:09

MarkJ


Declare a reference to Kernel32.lib SetDllDirectory function:

Private Declare Function SetDllDirectory Lib "Kernel32" Alias     "SetDllDirectoryA" (ByVal path As String) As Long

Then set the Dll directory as follows:

SetDllDirectory App.path
like image 43
Mark Dietel Avatar answered Sep 30 '22 08:09

Mark Dietel