请问,VB6程序转成VB.net报Addressof表达式不能转换为long,因为long不是委托类型
请教,VB6程序转成VB.net报Addressof表达式不能转换为long,因为long不是委托类型
程序如下:
'-- UNZIP32.DLL Userfunctions Structure
Structure USERFUNCTION
Public UZDLLPrnt As Long ' Pointer To Apps Print Function
Public UZDLLSND As Long ' Pointer To Apps Sound Function
Public UZDLLREPLACE As Long ' Pointer To Apps Replace Function
Public UZDLLPASSWORD As Long ' Pointer To Apps Password Function
Public UZDLLMESSAGE As Long ' Pointer To Apps Message Function
Public UZDLLSERVICE As Long ' Pointer To Apps Service Function (Not Coded!)
Public TotalSizeComp As Long ' Total Size Of Zip Archive
Public TotalSize As Long ' Total Size Of All Files In Archive
Public CompFactor As Long ' Compression Factor
Public NumMembers As Long ' Total Number Of All Files In The Archive
Public cchComment As Integer ' Flag If Archive Has A Comment!
End Structure
Public Function FnPtr(ByVal lp As Long) As Long
FnPtr = lp
End Function
Public Function UZDLLPrnt(ByRef fname As UNZIPCBChar, ByVal x As Long) As Long
Dim s0 As String
Dim xx As Long
'-- Always Put This In Callback Routines!
On Error Resume Next
s0 = ""
'-- Gets The UNZIP32.DLL Message For Displaying.
For xx = 0 To x - 1
If fname.ch(xx) = 0 Then Exit For
s0 = s0 & Chr(fname.ch(xx))
Next
'-- Assign Zip Information
If Mid$(s0, 1, 1) = vbLf Then s0 = vbNewLine ' Damn UNIX :-)
UZDLLPrnt = 0
End Function
Public Function VBUnZip32(ByVal uzdcl As DCLIST, ByVal uZipNames As UNZIPnames, ByVal uNumberFiles As Long, ByVal uNumberXFiles As Long, _
ByVal uExcludeNames As UNZIPnames) As Long
Dim retcode As Long
Dim MsgStr As String
Dim UZUSER As USERFUNCTION
Dim UZVER As UZPVER
Dim _UZDLLPrnt = New delegateUZDLLPrnt(AddressOf UZDLLPrnt)
retcode = 1
'-- Set Callback Addresses
'-- (WARNING!!!) Do Not Change
UZUSER.UZDLLPrnt = FnPtr(AddressOf UZDLLPrnt)
UZUSER.UZDLLSND = 0& '-- Not Supported
UZUSER.UZDLLREPLACE = FnPtr(AddressOf UZDLLRep)
UZUSER.UZDLLPASSWORD = FnPtr(AddressOf UZDLLPass)
UZUSER.UZDLLMESSAGE = FnPtr(AddressOf UZReceiveDLLMessage)
UZUSER.UZDLLSERVICE = FnPtr(AddressOf UZDLLServ)
问题出在highlighted ,问题非常急,请各位帮忙,谢谢。
------解决方案--------------------
AddressOf 后面需要的参数是个和委托参数返回值一致 的方法
程序如下:
'-- UNZIP32.DLL Userfunctions Structure
Structure USERFUNCTION
Public UZDLLPrnt As Long ' Pointer To Apps Print Function
Public UZDLLSND As Long ' Pointer To Apps Sound Function
Public UZDLLREPLACE As Long ' Pointer To Apps Replace Function
Public UZDLLPASSWORD As Long ' Pointer To Apps Password Function
Public UZDLLMESSAGE As Long ' Pointer To Apps Message Function
Public UZDLLSERVICE As Long ' Pointer To Apps Service Function (Not Coded!)
Public TotalSizeComp As Long ' Total Size Of Zip Archive
Public TotalSize As Long ' Total Size Of All Files In Archive
Public CompFactor As Long ' Compression Factor
Public NumMembers As Long ' Total Number Of All Files In The Archive
Public cchComment As Integer ' Flag If Archive Has A Comment!
End Structure
Public Function FnPtr(ByVal lp As Long) As Long
FnPtr = lp
End Function
Public Function UZDLLPrnt(ByRef fname As UNZIPCBChar, ByVal x As Long) As Long
Dim s0 As String
Dim xx As Long
'-- Always Put This In Callback Routines!
On Error Resume Next
s0 = ""
'-- Gets The UNZIP32.DLL Message For Displaying.
For xx = 0 To x - 1
If fname.ch(xx) = 0 Then Exit For
s0 = s0 & Chr(fname.ch(xx))
Next
'-- Assign Zip Information
If Mid$(s0, 1, 1) = vbLf Then s0 = vbNewLine ' Damn UNIX :-)
UZDLLPrnt = 0
End Function
Public Function VBUnZip32(ByVal uzdcl As DCLIST, ByVal uZipNames As UNZIPnames, ByVal uNumberFiles As Long, ByVal uNumberXFiles As Long, _
ByVal uExcludeNames As UNZIPnames) As Long
Dim retcode As Long
Dim MsgStr As String
Dim UZUSER As USERFUNCTION
Dim UZVER As UZPVER
Dim _UZDLLPrnt = New delegateUZDLLPrnt(AddressOf UZDLLPrnt)
retcode = 1
'-- Set Callback Addresses
'-- (WARNING!!!) Do Not Change
UZUSER.UZDLLPrnt = FnPtr(AddressOf UZDLLPrnt)
UZUSER.UZDLLSND = 0& '-- Not Supported
UZUSER.UZDLLREPLACE = FnPtr(AddressOf UZDLLRep)
UZUSER.UZDLLPASSWORD = FnPtr(AddressOf UZDLLPass)
UZUSER.UZDLLMESSAGE = FnPtr(AddressOf UZReceiveDLLMessage)
UZUSER.UZDLLSERVICE = FnPtr(AddressOf UZDLLServ)
问题出在highlighted ,问题非常急,请各位帮忙,谢谢。
------解决方案--------------------
AddressOf 后面需要的参数是个和委托参数返回值一致 的方法
- VB.NET code
Dim hander As EventHandler = New EventHandler(AddressOf TestFun) '这里的方法必须和EventHandler 的参数和返回值一致 Public Sub TestFun(ByVal senser As Object, ByVal e As EventArgs) End Sub