W
William Morgan
Public Declare Sub ydec_set_callback Lib "yDecLib.dll" (ByVal CallbackFunc As Long)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As String, ByVal lpvSource As String, ByVal cbCopy As Long)
Private Function yDecEventHandler(ByVal MsgType As Long, ByVal Data As Long, ByVal Msg As Long, ByVal MsgSize As Long) As Long
' this function handles all events fired by the decoder library
' for most events, returning 0 will cancel the decoding process; returning 1
' will continue normally
Dim MsgStr As String
' allocate buffer to receive text message string, then copy the message
' to our buffer - be sure to check MsgSize first; some events don't have
' message text associated with them
If MsgSize > 0 Then
Dim i As Integer
MsgStr = New String(" ", MsgSize)
CopyMemory(MsgStr, Msg, MsgSize)
End If
' on YDEC_MSG_PROGRESS events, returning 0 will abort the decoding process
yDecEventHandler = 1
' determine what type of message this is, and act appropriately
Select Case MsgType
'Case Is = YDEC_MSG_ADD_OK
' file was successfully added to the input file list
' you probably don't need to handle this, but it's here anyway
' frmMain.lstMessages.AddItem("Added file: " & MsgStr & " (file #" & Data + 1 & ")")
Case Is = 1
' occasionally called to allow your application to update a
' progress meter, refresh a window, etc.
' frmMain.ProgressBar.Value = Data
Case Is = 2
' starting to decode a file part
'frmMain.lstMessages.AddItem("Decoding part #" & Data & " of file " & MsgStr)
Case Is = 3 ' YDEC_MSG_PART_OK
' file part was decoded successfully
'frmMain.lstMessages.AddItem("Successfully decoded part # " & Data & " of file " & MsgStr)
Case Is = 4
' file part was corrupt
'frmMain.lstMessages.AddItem("Error: part # " & Data & " of file " & MsgStr & " is corrupt!")
Case Is = 5 'YDEC_MSG_FILE_OK
' entire file was decoded successfully
'frmMain.lstMessages.AddItem("Successfully decoded file " & MsgStr & " (" & Data & " bytes)")
MsgBox("Filedone")
Case Is = 6 'YDEC_MSG_FILE_INCOMPLETE
' file was missing one or more parts
'frmMain.lstMessages.AddItem("Error: file " & MsgStr & " is missing one or more parts!")
Case Is = 7 'YDEC_MSG_FILE_CORRUPT
' file was complete, but corrupt
'frmMain.lstMessages.AddItem("Error: file " & MsgStr & " is corrupt! (" & Data & " bytes)")
Case Is = 8 'YDEC_MSG_NOTICE
' miscellaneous warning messages from the decoder library
MsgBox("Notice: " & MsgStr)
Case Else
MsgBox("Received unsupported event message from yDecoder library!", vbOKOnly, "Error")
End Select
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ydec_set_callback(AddressOf yDecEventHandler)
End Sub
how do you set the callback now that you can't use the addressof?
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal lpvDest As String, ByVal lpvSource As String, ByVal cbCopy As Long)
Private Function yDecEventHandler(ByVal MsgType As Long, ByVal Data As Long, ByVal Msg As Long, ByVal MsgSize As Long) As Long
' this function handles all events fired by the decoder library
' for most events, returning 0 will cancel the decoding process; returning 1
' will continue normally
Dim MsgStr As String
' allocate buffer to receive text message string, then copy the message
' to our buffer - be sure to check MsgSize first; some events don't have
' message text associated with them
If MsgSize > 0 Then
Dim i As Integer
MsgStr = New String(" ", MsgSize)
CopyMemory(MsgStr, Msg, MsgSize)
End If
' on YDEC_MSG_PROGRESS events, returning 0 will abort the decoding process
yDecEventHandler = 1
' determine what type of message this is, and act appropriately
Select Case MsgType
'Case Is = YDEC_MSG_ADD_OK
' file was successfully added to the input file list
' you probably don't need to handle this, but it's here anyway
' frmMain.lstMessages.AddItem("Added file: " & MsgStr & " (file #" & Data + 1 & ")")
Case Is = 1
' occasionally called to allow your application to update a
' progress meter, refresh a window, etc.
' frmMain.ProgressBar.Value = Data
Case Is = 2
' starting to decode a file part
'frmMain.lstMessages.AddItem("Decoding part #" & Data & " of file " & MsgStr)
Case Is = 3 ' YDEC_MSG_PART_OK
' file part was decoded successfully
'frmMain.lstMessages.AddItem("Successfully decoded part # " & Data & " of file " & MsgStr)
Case Is = 4
' file part was corrupt
'frmMain.lstMessages.AddItem("Error: part # " & Data & " of file " & MsgStr & " is corrupt!")
Case Is = 5 'YDEC_MSG_FILE_OK
' entire file was decoded successfully
'frmMain.lstMessages.AddItem("Successfully decoded file " & MsgStr & " (" & Data & " bytes)")
MsgBox("Filedone")
Case Is = 6 'YDEC_MSG_FILE_INCOMPLETE
' file was missing one or more parts
'frmMain.lstMessages.AddItem("Error: file " & MsgStr & " is missing one or more parts!")
Case Is = 7 'YDEC_MSG_FILE_CORRUPT
' file was complete, but corrupt
'frmMain.lstMessages.AddItem("Error: file " & MsgStr & " is corrupt! (" & Data & " bytes)")
Case Is = 8 'YDEC_MSG_NOTICE
' miscellaneous warning messages from the decoder library
MsgBox("Notice: " & MsgStr)
Case Else
MsgBox("Received unsupported event message from yDecoder library!", vbOKOnly, "Error")
End Select
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ydec_set_callback(AddressOf yDecEventHandler)
End Sub
how do you set the callback now that you can't use the addressof?