Using declare to call DLL from app.path

R

raajitlall

I am using this statement to call a DLL and it works fine.

Declare Sub M_STAR Lib "\\enaus00002512\Jer's Pub\mstarexcel\mstar.dll"
(One As Long, bs As Single, Hcff As Long, ByVal Vf As String, L As Long
.....

Now what I want to do is something like this ....


Declare Sub M_STAR Lib app.path & "mstar.dll" (One As Long, bs As
Single, Hcff As Long, ByVal Vf As String, L As Long ....


but VB6 does not allow me to do that. I cannot register this DLL so I
have to use the declare statement. Is there any other way I can call
the DLL from the folder that the application is in?

Raajit
 
D

Dr. Stephan Kassanke

In
I am using this statement to call a DLL and it works fine.

Declare Sub M_STAR Lib "\\enaus00002512\Jer's
Pub\mstarexcel\mstar.dll" (One As Long, bs As Single, Hcff As Long,
ByVal Vf As String, L As Long ....

Now what I want to do is something like this ....


Declare Sub M_STAR Lib app.path & "mstar.dll" (One As Long, bs As
Single, Hcff As Long, ByVal Vf As String, L As Long ....


but VB6 does not allow me to do that. I cannot register this DLL so I
have to use the declare statement. Is there any other way I can call
the DLL from the folder that the application is in?

Raajit

Dear Raajit,

I once had a similar problem in VBA. My solution was to declare the DLL
functions without any fixed paths, in your case:

Declare Sub M_STAR Lib "mstar.dll" (One As Long, bs As
Single, Hcff As Long, ByVal Vf As String, L As Long ....


The trick was to point my app to the specific DLL in the app path on
initializing. The following works for me (in Excel):

myPathSep = Application.PathSeparator
mydll = ThisWorkbook.path & myPathSep & "yourdll.dll"
rc = LoadLibrary(mydll)

The declare statements do not access the dll but just declare the functions.
Upon initialization I pointed my app by the LoadLibrary statement to the
dll in the app path.

cheers,
Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top