Variable path to library?

C

Cory

I am Declaring a function from an external library that exists in different
directories on a number of users computers. I have successfully found the
programs directory entry in the registry and I can pull that value, but it
does not look like I can specify the path to the library in the declare
statement with a variable (the path). Anyone know a way around this?

I am programming this in publisher, so if you are thinking of adding a
reference object for the library, know that I have not yet found a way to do
that since publisher does not seem to have a way of accessing a projects
references as objects.

I am using Publisher 2003 and Windows XP if that makes any difference. Any
help would be appreciated.

Cory
 
J

jaf

Hi Cory,
If the lib is properly registered you don't need a path.
You could write a one liner to test for the lib prior to executing the
function. If its not found/registered its going to fail anyway.

John
 
C

Cory

By registered you mean in the registry with GUID and everything... Hopefully
I can get access to the registry and find the entry. They have our systems
locked down pretty tight.

Also, if it is registered properly, I will just need the name of the library
without path, right?

Cory
 
K

Karl E. Peterson

Cory said:
I am Declaring a function from an external library that exists in different
directories on a number of users computers.

I take it, by that, that you are really doing what you say you are? That is,
writing a Declare for it, like you might SendMessage or any other standard DLL call?
That this isn't an ActiveX library, from which you are creating OLE objects, like
FSO and such?
I have successfully found the
programs directory entry in the registry and I can pull that value, but it
does not look like I can specify the path to the library in the declare
statement with a variable (the path). Anyone know a way around this?

Yes. Write the Declare without a path. The next step depends on how often you need
to call the library. If just once, you can change to the library folder, make the
call, and change back...

' Store current directory, to switch back to later.
' Switch to path that OE is installed in.
StartDir = CurDir()
ChDrive Path
ChDir Path

' Just for kicks, make sure we can load library and find procaddr.
If Exported(LibraryFile, FunctionName) Then
Call FunctionName(&H3F&, Dummy, 1)
Success = True
End If

' Restore former drive/path
ChDrive StartDir
ChDir StartDir

See http://vb.mvps.org/samples/project.asp?id=MultiOE for an example that does this
to start multiple instances of Outlook Express.

Another approach, if you need to call the function repeatedly, would be to load the
library explicitly (using LoadLibrary) prior to calling any functions in it. Again,
no path required in your Declare, but of course you will need to point directly at
the desired file in the LoadLibrary call.
 
C

Cory

Yup. Specifically this Declare statement calls the Calc_Lat_Long function
from Geo32.dll which is a file associated with a mapping program. The
program may not be installed in the same place on every computer since
several entities are going to be using it. The declare statement that I have
so far is:
Private Declare Function GEO_calc_lat_lon Lib "c:\PFPS\system\Geo32.dll"
Alias "CalcLatLong" (ByVal MGRS As String, ByVal Datum As Integer, ByRef
Latitude As Double, ByRef Longitude As Double) As Integer

I tried Lib PFPSPath & "\system\Geo32.dll" where PFPSPath is a Global
variable that is filled with the value of a registry entry that contains the
PFPS root folder path. If there were a way to dynamically change the actual
string that follows the lib I don't know it.

Cory
 
K

Karl E. Peterson

Cory said:
Yup. Specifically this Declare statement calls the Calc_Lat_Long function
from Geo32.dll which is a file associated with a mapping program. The
program may not be installed in the same place on every computer since
several entities are going to be using it. The declare statement that I have
so far is:
Private Declare Function GEO_calc_lat_lon Lib "c:\PFPS\system\Geo32.dll"
Alias "CalcLatLong" (ByVal MGRS As String, ByVal Datum As Integer, ByRef
Latitude As Double, ByRef Longitude As Double) As Integer

I'm suspicious those Integer references should be Long - were the docs written for C
programmers? Anyway, you'd likely want to rewrite it like this:

Private Declare Function CalcLatLong Lib "geo32.dll"(ByVal MGRS As String, ByVal
Datum As Long, ByRef Latitude As Double, ByRef Longitude As Double) As Long

I didn't mess with the Alias, because you used two different export names in your
post, so I have no idea which is what.
I tried Lib PFPSPath & "\system\Geo32.dll" where PFPSPath is a Global
variable that is filled with the value of a registry entry that contains the
PFPS root folder path. If there were a way to dynamically change the actual
string that follows the lib I don't know it.

The way is as I told you below. You can either call LoadLibrary on the
fully-qualified DLL, or change the current directory to the one in which it resides
prior the first time you call this function.
--
..NET: It's About Trust!
http://vfred.mvps.org


 

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