Re: Variable path to library?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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



.



Relevant Pages

  • Re: make general windows module
    ... The VB version of these declarations is the "Declare Statement". ... mimicing the behavior of a "windows.h" header file for VB. ... not all Windows API calls can be called from VB as some use reference ...
    (microsoft.public.vb.general.discussion)
  • Re: portable way of strict type checking in defun
    ... If you want to make a macro, ... that returns the PROGN form you wrote above, and it should work just fine. ... But compiled versions of the function with declare statement has ...
    (comp.lang.lisp)
  • Re: Creating objects (by assignment) in VB6
    ... the Declare statement should never be used in ... A typelib is essentially 'hidden' away during development. ... advantage, wich comes from the ommited Err-Object-check, ... wich is always performed in case of a "normal Declare". ...
    (microsoft.public.vb.enterprise)
  • Re: declaring vars in a group more performant ?
    ... versus many variable declarations is the cost of lexing/parsing the code, ... DECLARE statement for each variable? ... DECLARE @var1 int, @var2 int ...
    (microsoft.public.sqlserver.programming)