Hi there,
I'm Mikito Matsui.
I have a question about the DLL.
I'd like to call a function (let's say this is "foo") in a DLL (let's say this is "DLL_A") from another DLL (let's say this is "DLL_B"). Would you tell me how to do this ?
(Windows 7 Professional / Microsoft Visual Basic 6.0)
I was able to call the "foo" in "DLL_A" by using declare function as follows.
Declare Function foo Lib "Dll_A.dll" _
(ByRef val1 As Any, ByVal val2 As Long, _
ByVal val3 As Long, ByVal val4 As Long, _
ByRef val5 As Any) As Long
return = foo(val1, val2, val3, val5, val6)
Then, I made "Dll_B" by using ActiveX Dll of Visual Basic 6. (I used the code below as reference.) "DLL_B" is as follows.
Private Function bar(val1 As Long, val2 As Long, val3 As Long, val4 As Long, val5 As L ong)
On Error Resume Next
Dim lb As Long, pa As Long
lb = LoadLibrary("Dll_A")
pa = GetProcAddress(lb, "foo")
CallWindowProc pa, ByVal val1, ByVal val2, ByVal val3, ByVal val4, ByVal val5
FreeLibrary lb
End Function
The code which I used as reference is as follows.
Create a New project And add this code To Form1
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 Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Sub Form_Load()
On Error Resume Next
Dim lb As Long, pa As Long
lb = LoadLibrary("user32")
pa = GetProcAddress(lb, "SetWindowTextA")
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
FreeLibrary lb
End Sub
I called the "bar" by using declare function in the same way as "DLL_A" as follows.
Declare Function bar Lib "Dll_B.dll" _
(ByRef val1 As Any, ByVal val2 As Long, _
ByVal val3 As Long, ByVal val4 As Long, _
ByRef val5 As Any) As Long
return = bar(val1, val2, val3, val4, val5)
But I execute this code, the following error displays.
Run-time error '453' Can't find DLL entry point "bar" in "DLL_B"
I tried to call "bar" as follows, but the error displays as well.
Dim objB As Object
set objB = CreateObject("Project1.Class1")
call objB.bar()
set objB = Nothing
After I registered the "DLL_B" with the registry, the error still displays.
Please tell me the solution strategy or give me a clue. Thank you all in advance.
Best regards
Mikito Matsui