|
|
|
date: Mon, 23 Jun 2008 06:38:02 -0700,
group: microsoft.public.office.developer.vba
back
Re: Variable path to library?
Cory wrote:
> 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.
--
.NET: It's About Trust!
http://vfred.mvps.org
date: Tue, 24 Jun 2008 13:01:29 -0700
author: Karl E. Peterson
Re: Variable path to library?
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
"Karl E. Peterson" wrote:
> Cory wrote:
> > 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.
> --
> ..NET: It's About Trust!
> http://vfred.mvps.org
>
>
>
date: Tue, 24 Jun 2008 14:58:00 -0700
author: Cory
Re: Variable path to library?
Cory wrote:
> 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
>> Cory wrote:
>> > 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.
>> --
>> ..NET: It's About Trust!
>> http://vfred.mvps.org
date: Tue, 24 Jun 2008 15:19:04 -0700
author: Karl E. Peterson
|
|