I need to create a wrapper for the DLL, load and unload it as needed (for those who are interested in the background of this question, see How to work with memory leak of a third-party DLL (without source code), accessible by Tomcat application? ) I do this in Visual Basic 6, and loading and unloading in the following example:
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Sub cmdTestLoadingDLL_Click()
Dim lb As Long, pa As Long
lb = LoadLibrary("D:\projects\other\VB_DLLs\TestDLL\TestDLL.dll")
Msgbox "Library address: " + lb
FreeLibrary lb
End Sub
I see, using Process Explorer , that a DLL is loaded into memory when a message box is displayed, and then discarded. However, calling the method is naturally not enough - I need to access the methods in a dynamically loaded DLL.
How can i achieve this? I would like to call the getVersion method in the mainClass class, which is in TestDLL, for example:
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Sub cmdTestLoadingDLL_Click()
Dim lb As Long, pa As Long
Dim versionString As String
lb = LoadLibrary("D:\projects\other\VB_DLLs\TestDLL\TestDLL.dll")
versionString = "- From DLL: " + mainClass.getVersion
MsgBox versionString
FreeLibrary lb
End Sub
However line
versionString = "- From DLL: " + mainClass.getVersion
" ".