6

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

Beppe
  • 381
  • 2
  • 7
  • 15
  • possible duplicate of [How can you force VB6 to use the DLLs and OCXs from the app directory?](http://stackoverflow.com/questions/345111/how-can-you-force-vb6-to-use-the-dlls-and-ocxs-from-the-app-directory) – JohnFx Mar 08 '11 at 15:25
  • @JohnFx my problem is that i _can't_ load it from the app directory, not that I load system32 dll before than app folder dll. – Beppe Mar 08 '11 at 15:40
  • @JohnFX and the others: this is **not** a duplicate of [How can you force VB6 to use the DLLs and OCXs from the app directory](http://stackoverflow.com/questions/345111/how-can-you-force-vb6-to-use-the-dlls-and-ocxs-from-the-app-directory). Please undo your votes to close. – MarkJ Mar 08 '11 at 15:58
  • @MarkJ - Even if I agreed with you. There is no way to undo a close vote. – JohnFx Mar 08 '11 at 16:40

5 Answers5

7

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.
MarkJ
  • 30,070
  • 5
  • 68
  • 111
  • 1
    This solution involves a runtime operation that I cannot afford as I need to load the dll in a implicit way through a .tlb file. I have seen other applications written in VB6 running with the DLLs in the same directory of the .exe. So there must be a solution (I hope) that does not involves the runtime computationof the path. – Beppe Mar 08 '11 at 16:10
  • @Beppe The reason is simple, so is the [workaround](http://stackoverflow.com/questions/154299/how-to-set-working-directory-when-debugging-vb6-app/154595#154595). – GSerg Mar 12 '11 at 00:41
3

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
Mark Dietel
  • 271
  • 3
  • 3
0

As Beppe said in their answer, use

Depends yourdll.dll

If you seel other DLLS with ? next to their name it means they are missing.
Usually it will be one of the Microsoft C++ Debug dll i.e MSVCR120D.DLL

rene
  • 41,474
  • 78
  • 114
  • 152
Steve
  • 1
0

Solved using "Depends"

There was an unsatisfied dependency in the DLL, but obviously it was returning the error on the first DLL entry point.

Thank you all

Beppe
  • 381
  • 2
  • 7
  • 15
  • Are you now getting the DLL to load implicitly? Does the TLS stuff work? I'm very keen to find out if this trick does indeed work. – David Heffernan Mar 08 '11 at 16:34
  • @David I succesfully referenced the .tlb file, but using `Declare Function` it still crash, so I guess the trick does not work in this sense. I'm trying to make it works only using the function declared in the .tlb, but atm I still have problems with Strings-BSTR-char-whatever (I guess is there the problem, or better, I hope) – Beppe Mar 08 '11 at 17:22
  • @beppe I don't think you did get it implicitly linked because the error with the missing dependency would have been triggered at startup. Have you checked in dependency walker that your exe refers to the dll? – David Heffernan Mar 08 '11 at 17:35
  • @David I tried to remove the dependencies and it stop to work, so I think it took the link. I also checked with Depends and it took the dependency. – Beppe Mar 08 '11 at 17:43
  • @beppe I ask again. Is the DLL in the EXE's import table? – David Heffernan Mar 08 '11 at 17:46
  • @David Yes it is, sorry if my answer was not so clear. I noticed that the MSVCR80.dll dependency has '?', but I don't know if it could be a problem – Beppe Mar 08 '11 at 17:51
  • @David To avoid the problem I temporaly changed the prototype of the function that was the cause of the "TLS" crash, taking off all the parameter (manually initializated inside the function). It still crashes when launched in the IDE, but it works if launched from the .EXE!! So the only problem left is regarding the string->char* conversion – Beppe Mar 09 '11 at 08:31
-1

You need to register your DLL first..

Shell "regsvr32.exe /s " & path

Where "path" is the path of the DLL.. If the DLL is placed in the same directory, then you can set:

path = App.path & "/myDLL.dll"

Ronald
  • 49
  • 1
  • 1