Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help needed to make declare function stmt more flexible

0 views
Skip to first unread message

john franklyn

unread,
Apr 23, 2002, 10:29:25 AM4/23/02
to
Hello all,
I'm trying to find a way to make the VB6 declare function statements more
flexible. I have the following example:
Declare Function odmPWAPI_Login Lib "C:\Program
Files\Bentley\PWExplorer\bin\esri_odma.dll" (ByVal user As String, ByVal pwd
As String, ByVal dsn As String) As Long

The path for the esri_odma.dll is based on registry entries and could be
different on every client machine. I'm trying to find out how I can modify
the Declare Function statement to take a variable for the DLL path. Any
input would be greatly appreciated. Thanks.


Paul Gentry

unread,
Apr 23, 2002, 10:59:18 AM4/23/02
to
Well you have to register DLLs to use them and if the DLL is registerd when
you call it you do not have to give the path so that should not be an issue.

"john franklyn" <john.f...@bentley.com> wrote in message
news:e1Pk0Kt6BHA.2276@tkmsftngp03...

Mike Kinasz

unread,
Apr 23, 2002, 11:02:39 AM4/23/02
to
I think the solution for you is to use a generic declare like this
Declare Function odmPWAPI_Login Lib "esri_odma.dll" _
(ByVal user As String, _
ByVal pwd As String, _

ByVal dsn As String) As Long

'***and before you call that DLL use
Declare Function LoadLibrary Lib "kernel32" Alias _
"LoadLibraryA" (ByVal _
lpLibFileName As String) As Long

strDir = somequalifiedpath to your dll
lngVal = LoadLibrary(strDir & "esri_odma.dll")
'0 on error... if 0 check Err.LastDllError

'***before you end the program use
Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) _
As Long
lngVal = FreeLibrary(strDir & "esri_odma.dll")


Give that a try..... I'm pretty sure that'll work.......
Mike

"john franklyn" <john.f...@bentley.com> wrote in message
news:e1Pk0Kt6BHA.2276@tkmsftngp03...

john franklyn

unread,
Apr 23, 2002, 11:25:30 AM4/23/02
to
Paul,
thanks for your help. The DLL I have is a regular DLL and not a COM DLL.
regsvr32 gives me a error when I try to register this DLL.
esri_odma.dll was loaded but the DllRegisterServer entry point was not
found.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Esh

unread,
Apr 23, 2002, 11:28:34 AM4/23/02
to

Declare it ~without~ the path in the lib argument. That way the system
will use it's standard search rules for lib loading, which are:
1. The directory from which the application loaded. (i.e. App.Path)
2. The current directory.
3. The system directory.
4. (NT) only: The 16-bit system directory.
5. Windows directory.
6. Directories that are listed in the PATH environment variable.

Rule #2 can cover a situation like you describe. VB loads libraries
when you make the first call to one of the declared methods. Retreive
the path from the registry and immediately before making the first
call, simply ChDrive and ChDir to that path. VB keeps libs loaded
until the app terminates, so once it's loaded you can restore/change
the current drive/dir as needed.
Alternatively you could call LoadLibrary yourself using the path
retreived from the registry. Note however it requires a complimentary
call to FreeLibrary when the app terminates in order to maintain the
lib usage counter.


-Tom
(please post replies to the newsgroup)

Tom Esh

unread,
Apr 23, 2002, 11:37:51 AM4/23/02
to
On Tue, 23 Apr 2002 07:59:18 -0700, "Paul Gentry"
<umm...@Hotmail.com> wrote:
>Well you have to register DLLs to use them and if the DLL is registerd when
>you call it you do not have to give the path so that should not be an issue.
That's only true for COM (activex) dlls, which don't use declare
statements. The declare requirement indicates it's not a COM lib.

john franklyn

unread,
Apr 23, 2002, 1:54:07 PM4/23/02
to
This worked very well. Thanks for your time.

MikeD

unread,
Apr 23, 2002, 9:04:56 PM4/23/02
to

"john franklyn" <john.f...@bentley.com> wrote in message
news:e1Pk0Kt6BHA.2276@tkmsftngp03...

You absolutely, positively can't. If you specify a path in the declaration,
that's the ONLY place Windows will look for the DLL and you absolutely,
positively cannot change that path at runtime. If the file is not in that
exact folder, the function call will fail, even if the DLL is in a folder
that Windows would normally search. You should omit the path, and the DLL
just needs to be in a folder that is one of the paths that Windows will
automatically search.

With that said, you *could* get the path from the Registry and then modify
the Path environment variable in autoexec.bat to include that path (you will
likely have to create autoexec.bat on some systems). The system would then
have to be rebooted. This might be OK to do in a work environment WITH the
admin/supervisor's approval (if you're the admin, so much the better). I
definately wouldn't recommend it for any other situatuation.

Perhaps somebody else has a better "solution".

Mike

MikeD

unread,
Apr 23, 2002, 9:10:06 PM4/23/02
to

"Mike Kinasz" <mki...@cbspayroll.com> wrote in message
news:OYdI2gt6BHA.2336@tkmsftngp03...

> I think the solution for you is to use a generic declare like this
> Declare Function odmPWAPI_Login Lib "esri_odma.dll" _
> (ByVal user As String, _
> ByVal pwd As String, _
> ByVal dsn As String) As Long
>
> '***and before you call that DLL use
> Declare Function LoadLibrary Lib "kernel32" Alias _
> "LoadLibraryA" (ByVal _
> lpLibFileName As String) As Long
>
> strDir = somequalifiedpath to your dll
> lngVal = LoadLibrary(strDir & "esri_odma.dll")
> '0 on error... if 0 check Err.LastDllError
>
> '***before you end the program use
> Declare Function FreeLibrary Lib "kernel32" _
> (ByVal hLibModule As Long) _
> As Long
> lngVal = FreeLibrary(strDir & "esri_odma.dll")
>
>
> Give that a try..... I'm pretty sure that'll work.......
> Mike
>

I never even thought of LoadLibrary (and I've even used that API function on
several occasions). Good call, even if you did make my reply look foolish.
<g>

Mike


0 new messages