Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
developer
active.documents
automation
binary.file_format
clipboard.dde
com.add_ins
hosting.controls
internet_other
office.sdks
officedev
officedev.other
outlook.forms
outlook.vba
smarttags
vba
web.components
  
 
date: Mon, 23 Jun 2008 06:38:02 -0700,    group: microsoft.public.office.developer.vba        back       


Variable path to library?   
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
date: Mon, 23 Jun 2008 06:38:02 -0700   author:   Cory

Re: Variable path to library?   
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


"Cory"  wrote in message 
news:33B0EA6F-7925-4A98-A754-B964C889DE16@microsoft.com...
>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
date: Mon, 23 Jun 2008 17:37:01 -0400   author:   jaf

Re: Variable path to library?   
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

"jaf" wrote:

> 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
> 
> 
> "Cory"  wrote in message 
> news:33B0EA6F-7925-4A98-A754-B964C889DE16@microsoft.com...
> >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 
> 
>
date: Mon, 23 Jun 2008 22:05:00 -0700   author:   Cory

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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us