如何调用另一个DLL中的函数? (Win7的/ VB6.0)

时间:2014-07-17 05:13:13

标签: dll vb6

我想从另一个DLL中调用一个函数(假设这是“foo”)(假设这是“DLL_A”)(假设这是“DLL_B”)。你能告诉我怎么做吗?

我可以使用declare函数调用“DLL_A”中的“foo”,如下所示。

'standard module
    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

'form
    return = foo(val1, val2, val3, val5, val6)

然后,我使用Visual Basic 6.0的ActiveX Dll制作了“Dll_B”。 (我使用下面的代码作为参考。)“DLL_B”如下。

'/*******************************************************************
'/*     DLL_B
'/*******************************************************************
Private Function bar(val1 As Long, val2 As Long, val3 As Long, val4 As Long, val5 As L        ong)
On Error Resume Next
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
lb = LoadLibrary("Dll_A")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "foo")
'Call the SetWindowTextA-function
CallWindowProc pa, ByVal val1, ByVal val2, ByVal val3, ByVal val4, ByVal val5
'unmap the library's address
FreeLibrary lb
End Function

我用作参考的代码如下。

'/*******************************************************************
'/*     The code which I used as reference. 
'/*******************************************************************
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
'We're going to call an API-function, without declaring it!
Dim lb As Long, pa As Long
'map 'user32' into the address space of the calling process.
lb = LoadLibrary("user32")
'retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "SetWindowTextA")
'Call the SetWindowTextA-function
CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
'unmap the library's address
FreeLibrary lb
End Sub

我通过使用declare函数调用“bar”,方法与“DLL_A”相同,如下所示。

'standard module
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

'form
return = bar(val1, val2, val3, val4, val5)

但是我执行此代码,显示以下错误。

  

运行时错误'453'在“DLL_B”中找不到DLL入口点“bar”

我尝试按如下方式调用“bar”,但也会显示错误。

Dim objB As Object
set objB = CreateObject("Project1.Class1")
call objB.bar()
set objB = Nothing

使用注册表注册“DLL_B”后,仍会显示错误。

请告诉我解决方案策略或给我一个线索。

0 个答案:

没有答案