Variable to declare function lib location?

H

hafabee

I call several functions in an external dll file. I would like to avoid
placing the dll in the system32 folder. I tried regsvr32 but the dll
has no entry point define for this.

If I put this in my module it works fine: Public Declare Function
my_function Lib "c:\My App\my.dll"

My question is: Is there any way I can somehow use a variable for the
folder instead of hard-coding "c:\My App\"? Specifically, I have a
registry setting with the folder name that I want to use.

I cannot figure out how to do this.

Thanks.
Hafabee
 
K

Karl E. Peterson

hafabee said:
I call several functions in an external dll file. I would like to
avoid placing the dll in the system32 folder. I tried regsvr32 but
the dll has no entry point define for this.

If I put this in my module it works fine: Public Declare Function
my_function Lib "c:\My App\my.dll"

My question is: Is there any way I can somehow use a variable for the
folder instead of hard-coding "c:\My App\"? Specifically, I have a
registry setting with the folder name that I want to use.

I cannot figure out how to do this.

One way I've used is to cache the curdir, switch to the dir that holds the
DLL, make the call, then reset the curdir back to what it was. You can also
use LoadLibrary manually, before making any calls to the DLL. Either should
allow you to avoid fully-qualifying the filename.
 
J

Jezebel

MyLib = "D:\funnyfolder\funnylib.dll"
activedocument.VBProject.References.AddFromFile FileName:=MyLib
 
D

Dian D. Chapman, MVP

(HEY! Who let YOU in here???<vbeg> Man...you must be really bored,
eh?<g>)

Dian ~
 
J

Jonathan West

Jezebel said:
MyLib = "D:\funnyfolder\funnylib.dll"
activedocument.VBProject.References.AddFromFile FileName:=MyLib
Hi Jezebel,

I think that would only work for an ActiveX DLL that had been registered,
and Hafabee has indicated that this isn't one of those, as a call to
regsvr32 doesn't work. Karl's approach is the way to go.
 
J

Jezebel

Using this method doesn't require the DLL to have been registered (although
registration is indeed a side effect of using it) -- it's the VBA equivalent
of using Tools > References > Browse.
 
H

hafabee

Karl said:
One way I've used is to cache the curdir, switch to the dir that holds the
DLL, make the call, then reset the curdir back to what it was.

Thanks, Karl, worked like a charm!

- Hafabee
 
K

Karl E. Peterson

Jezebel said:
Using this method doesn't require the DLL to have been registered
(although registration is indeed a side effect of using it) -- it's
the VBA equivalent of using Tools > References > Browse.

YeahButt... I understood the goal was to call exports from this library,
through a non-qualified Declare statement? Does this method do a
LoadLibrary? If so, that's an interesting twist.
 
K

Karl E. Peterson

(HEY! Who let YOU in here???<vbeg> Man...you must be really bored,
eh?<g>)

Yeah, I come here on slow days to spread the glory of the Win32 SDK, and
confuse the bejeebers out of folks hooked on these silly object models...
<eg>
 
D

Dian D. Chapman, MVP

HA!

(Hope all's well at your end.<wink>)

D ~

Yeah, I come here on slow days to spread the glory of the Win32 SDK, and
confuse the bejeebers out of folks hooked on these silly object models...
<eg>
 

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