以下是引用wmf2014在2016-6-11 12:41:37的发言:
vb里调用回调函数需要用到api,目前我还没找到回调函数传递参数的方法,实现你要求的变通方法如下:
'module1中代码
Function a() As Integer
a = Form1.x
End Function
Function b() As Integer
b = Form1.y
End Function
'form1中代码
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public x As Integer, y As Integer
Public Function c(ByVal a As Long, ByVal b As Long) As Long
c = CallWindowProc(a, 0, 0, 0, 0) + CallWindowProc(b, 0, 0, 0, 0)
End Function
Private Sub Command1_Click()
Label1.Caption = c(AddressOf a, AddressOf b)
End Sub
Private Sub Form_Load()
x = 3
y = 6
End Sub
'运行后会在标签中显示结果9
'module1中代码
Function a() As String
a = Form1.x
End Function
Function b() As String
b = Form1.y
End Function
'form1中代码
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public x As String, y As String
Public Function c(ByVal aCopy As Long, ByVal bCopy As Long) As String
c = CallWindowProc(aCopy, 0, 0, 0, 0) & vbCrLf & CallWindowProc(bCopy, 0, 0, 0, 0)
End Function
Private Sub Command1_Click()
Label1.Caption = c(AddressOf a, AddressOf b)
End Sub
Private Sub Form_Load()
x = "Very"
y = "Good"
End Sub
为何运行后会在标签中显示结果只有两个地址值而不是两个字符串的输出?