PC Review


Reply
Thread Tools Rate Thread

Call dll in variable location

 
 
=?Utf-8?B?U3ZlbiBEYWVtcw==?=
Guest
Posts: n/a
 
      13th Jun 2005
Hy group

I've a declaration of a function where I point to a .dll file. But I'd like
to connect to the .dll file using a variable. See the example for more
information.

Now, I'm using:
Declare Function LDBUser_GetUsers Lib "C:\CountUsersConnectedToDatabase.DLL" _
(lpszUserBuffer() As String, ByVal lpszFilename As String, _
ByVal nOptions As Long) As Integer

But I'de like to put the "C:\CountUsersConnectedToDatabase.DLL" in a string
because it will probably change of location. I allready tried the following
but it didn't work.

Declare Function LDBUser_GetUsers Lib strPathDLL_
(lpszUserBuffer() As String, ByVal lpszFilename As String, _
ByVal nOptions As Long) As Integer

Does anybody has an idea?

Thanxs
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      13th Jun 2005
you can use following approach:
Private Declare Function GetModuleHandle Lib "kernel32" Alias
"GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA"
(ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As
Long) As Long


a proc:

strDllPath="C:\CountUsersConnectedToDatabase.DLL"
hModule = GetModuleHandle(strDllPath)
If hModule = 0 Then
' need to load module into this process.
hModule = LoadLibrary(strDllPath & "irun.dll")
FreeLib = True
End If

call LDBUser_GetUsers (...)

If FreeLib Then Call FreeLibrary(hModule)


--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com


"Sven Daems" <(E-Mail Removed)> wrote in message
news:ED8A4119-B6E5-459F-9C4B-(E-Mail Removed)...
> Hy group
>
> I've a declaration of a function where I point to a .dll file. But I'd
> like
> to connect to the .dll file using a variable. See the example for more
> information.
>
> Now, I'm using:
> Declare Function LDBUser_GetUsers Lib
> "C:\CountUsersConnectedToDatabase.DLL" _
> (lpszUserBuffer() As String, ByVal lpszFilename As String, _
> ByVal nOptions As Long) As Integer
>
> But I'de like to put the "C:\CountUsersConnectedToDatabase.DLL" in a
> string
> because it will probably change of location. I allready tried the
> following
> but it didn't work.
>
> Declare Function LDBUser_GetUsers Lib strPathDLL_
> (lpszUserBuffer() As String, ByVal lpszFilename As String, _
> ByVal nOptions As Long) As Integer
>
> Does anybody has an idea?
>
> Thanxs



 
Reply With Quote
 
=?Utf-8?B?U3ZlbiBEYWVtcw==?=
Guest
Posts: n/a
 
      13th Jun 2005
Alex

Thanxs for you're help but I didn't find the solution yet.

Now, I've several lines off declaring:

Declare Function LDBUser_GetUsers Lib "C:\CountUsersConnectedToDatabase.DLL" _
(lpszUserBuffer() As String, ByVal lpszFilename As String, _
ByVal nOptions As Long) As Integer
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA"
(ByVal lpModuleName As String) As Long
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal
lpLibFileName As String) As Long
Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

and the function:

Public Function GetUsers(Optional StrDbPath As String)

ReDim lpszUserBuffer(1) As String
Dim Cusers As Long
Dim strMsgBox, strDllPath As String
Dim hModule As Long
Dim FreeLib As Boolean


strDllPath = Left(CurrentDb.Name, Len(CurrentDb.Name) - 3) & "dll"
hModule = GetModuleHandle(strDllPath)
If hModule = 0 Then
' need to load module into this process.
hModule = LoadLibrary(strDllPath & "irun.dll")
FreeLib = True
End If
If FreeLib = True Then Call FreeLibrary(hModule)

Cusers = LDBUser_GetUsers(lpszUserBuffer(), StrDbPath, 2)
MsgBox Cusers

End Function

I don't understand, why are you adding "irun.dll" to LoadLibrary (if I try
to leave it, it gives an error).
The code seems to run fine, but actually it doesn't do a thing..., it just
generates an error by Cusers = LDBUser_GetUsers(lpszUserBuffer(), StrDbPath,
2)

Thanxs

btw, strDllPath = Left(CurrentDb.Name, Len(CurrentDb.Name) - 3) & "dll"
gives the path and correct name of the .dll file. It has the same name & path
as the DB but instead of .mdb it is called .dll
 
Reply With Quote
 
Alex Dybenko
Guest
Posts: n/a
 
      13th Jun 2005
oops, sorry
hModule = LoadLibrary(strDllPath & "irun.dll")
should be
hModule = LoadLibrary(strDllPath)

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com



"Sven Daems" <(E-Mail Removed)> wrote in message
news:42CED766-E16A-4E36-988E-(E-Mail Removed)...
> Alex
>
> Thanxs for you're help but I didn't find the solution yet.
>
> Now, I've several lines off declaring:
>
> Declare Function LDBUser_GetUsers Lib
> "C:\CountUsersConnectedToDatabase.DLL" _
> (lpszUserBuffer() As String, ByVal lpszFilename As String, _
> ByVal nOptions As Long) As Integer
> Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA"
> (ByVal lpModuleName As String) As Long
> Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal
> lpLibFileName As String) As Long
> Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As
> Long
>
> and the function:
>
> Public Function GetUsers(Optional StrDbPath As String)
>
> ReDim lpszUserBuffer(1) As String
> Dim Cusers As Long
> Dim strMsgBox, strDllPath As String
> Dim hModule As Long
> Dim FreeLib As Boolean
>
>
> strDllPath = Left(CurrentDb.Name, Len(CurrentDb.Name) - 3) & "dll"
> hModule = GetModuleHandle(strDllPath)
> If hModule = 0 Then
> ' need to load module into this process.
> hModule = LoadLibrary(strDllPath & "irun.dll")
> FreeLib = True
> End If
> If FreeLib = True Then Call FreeLibrary(hModule)
>
> Cusers = LDBUser_GetUsers(lpszUserBuffer(), StrDbPath, 2)
> MsgBox Cusers
>
> End Function
>
> I don't understand, why are you adding "irun.dll" to LoadLibrary (if I try
> to leave it, it gives an error).
> The code seems to run fine, but actually it doesn't do a thing..., it just
> generates an error by Cusers = LDBUser_GetUsers(lpszUserBuffer(),
> StrDbPath,
> 2)
>
> Thanxs
>
> btw, strDllPath = Left(CurrentDb.Name, Len(CurrentDb.Name) - 3) & "dll"
> gives the path and correct name of the .dll file. It has the same name &
> path
> as the DB but instead of .mdb it is called .dll



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a variable to call a variable preiously set. Richhall Windows XP General 8 19th Sep 2008 03:34 PM
Re: How to call a macro at another location Tom Microsoft Excel Misc 1 23rd Dec 2007 01:14 AM
How to call up a macro in a different location? Tom Microsoft Excel Misc 1 18th Dec 2007 12:29 AM
Location of dll (API-function call) Jos Vens Microsoft Excel Programming 6 30th Jan 2006 03:59 PM
call a sub using a variable =?Utf-8?B?c21rMjM=?= Microsoft Access VBA Modules 10 28th Jun 2005 06:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:59 PM.