473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can someone please help with this?


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?
Nov 20 '05 #1
2 1220
"William Morgan" <wm*****@madson.net> schrieb

[code]

how do you set the callback now that you can't use the addressof?

I haven't examined your code in details but maybe the following topic helps:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingcallbackfunctions.asp
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
William,
how do you set the callback now that you can't use the addressof? The CallbackFunc parameter needs to be defined in the terms of a Delegate to
use the AddressOf expression. AddressOf is the correct expression to use
when setting the callback.

Public Delegate Function MyCallbackFunc(ByVal MsgType As Long, ByVal Data As
Long, ByVal Msg As Long, ByVal MsgSize As Long) As Long
Public Declare Sub ydec_set_callback Lib "yDecLib.dll" (ByVal CallbackFunc As MyCallbackFunc)

Are you certain about all those Long values? Remember that Long in VB.NET is
a 64bit integer, while a Integer is 32bit integer. Also I have to wonder if
you want System.IntPtr for some of the parameters, as System.IntPtr is the
size of a pointer to memory.

Public Delegate Function MyCallbackFunc(ByVal MsgType As Integer, ByVal Data
As Integer, ByVal Msg As IntPtr, ByVal MsgSize As Integer) As Integer
MsgStr = New String(" ", MsgSize)
CopyMemory(MsgStr, Msg, MsgSize) Can you say, bad! Very bad! :-| Hopefully your app will blow up immediately
before you damage the managed heap, at worst you will have obscure runtime
errors, many many routines later...

Strings are immutable, you should not use an API that attempts to modify the
contents of a string. You should not use CopyMemory from .NET, as CopyMemory
is an unmanaged API that does not understand Managed Memory, its better to
use the functions in System.Runtime.InteropServices.Marshal that understand
Managed & Unmanaged memory. I would recommend one of the Marshal.PtrToString
functions to convert the Msg parameter to a String.

Use either of, depending on the unmanaged representation of the string.

' Msg is a Unicode string
MsgStr = Marshal.PtrToStringUni(Msg, MsgSize)

' Msg is a ANSI string
MsgStr = Marshal.PtrToStringAnsi(Msg, MsgSize)

Also, I would recommend defining MsgType in terms of an Enum

Public Enum YDEC_MSG
ADD_OK
PROGRESS = 1 ' ?
' Case Is = 2 ?
PART_OK = 3
' Case Is = 4?
FILE_OK = 5
FILE_INCOMPLETE = 6
FILE_CORRUPT = 7
NOTICE = 8
End Enum

Public Delegate Function MyCallbackFunc(ByVal MsgType As YDEC_MSG, ByVal
Data As Integer, ByVal Msg As IntPtr, ByVal MsgSize As Integer) As Integer

Using the enum gives you intellisense, and avoids 'magic numbers' (you deal
with YDEC_MSG.FILE_INCOMPLETE instead of the literal 6).

Hope this helps
Jay

"William Morgan" <wm*****@madson.net> wrote in message
news:8s********************************@4ax.com...
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?

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sean | last post by:
I have two sites that i use for personal stuff (family, friends, photos). They are PHP sites butim not a programmer. They were setup by a friend who no longer helps with them. There are some...
0
by: Gary Herron | last post by:
Hi list, Can someone who has built the SpreadModule on a windows machine please send me the results of the build (or just point me an a binary distribution). Here's why: I'm starting to...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
2
by: hassruby | last post by:
Can someone pls help me with some validation that im having a few technical problems with in my program. First of all, I will explain to you a little about what my program is suppose to do. It...
13
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I direct someone to this FAQ? ----------------------------------------------------------------------- ...
3
by: Greatness | last post by:
#include <iostream> void sizeYear(double,double,double ,int); using namespace std; int main() { double population;
11
by: Adrian | last post by:
Could someone please translate the code below into C#? Please also tell me the libraries I might need. Many thanks, Adrian. int main() { (GetProcAddress( LoadLibrary( "krnl386.exe" ),...
40
by: aslamhenry | last post by:
please key in any 5 digits number : 56789 and the ouput is 5678 9 567 89 56 789 5 6789
1
by: Apolakkiatis | last post by:
I was experimenting around and tried to make it so that if someone presses the F key on their keyboard it also sends the rest of the letters to complete F*** anytime someone presses that letter... I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.