Calling DLL in VB.Net

H

Hannibal111111

I have a program which I upgraded from VB6 that has a call to a DLL.
Below is the code (some of which may not be correct, IE my delegate
functions):

Delegate Function EnumEncodingIntDelegate(ByVal lpszWavFile As String,
ByVal lpszOutFile As String, ByVal Bitrate As Integer, ByVal
SampleRate As Integer, ByVal EncMode As EncodeMode, ByRef lpCallback
As Integer) As Integer

Delegate Function EnumEncodingStringDelegate(ByVal lpszWavFile As
String, ByVal lpszOutFile As String, ByVal Bitrate As Integer, ByVal
SampleRate As Integer, ByVal EncMode As EncodeMode, ByRef lpCallback
As String) As Integer

Delegate Function EnumEncodingBoolDelegate(ByVal lpszWavFile As
String, ByVal lpszOutFile As String, ByVal Bitrate As Integer, ByVal
SampleRate As Integer, ByVal EncMode As EncodeMode, ByRef lpCallback
As Boolean) As Integer

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal
lpszWavFile As String, ByVal lpszOutFile As String, ByVal Bitrate As
Integer, ByVal SampleRate As Integer, ByVal EncMode As EncodeMode,
ByRef lpCallback As EnumEncodingIntDelegate) As Integer

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal
lpszWavFile As String, ByVal lpszOutFile As String, ByVal Bitrate As
Integer, ByVal SampleRate As Integer, ByVal EncMode As EncodeMode,
ByRef lpCallback As EnumEncodingStringDelegate) As Integer

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal
lpszWavFile As String, ByVal lpszOutFile As String, ByVal Bitrate As
Integer, ByVal SampleRate As Integer, ByVal EncMode As EncodeMode,
ByRef lpCallback As EnumEncodingBoolDelegate) As Integer

Here is the original vb6 code:

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal lpszWavFile
As String, ByVal lpszOutFile As String, ByVal Bitrate As Long, ByVal
SampleRate As Long, ByVal EncMode As EncodeMode, lpCallback As Any) As
Long

This is how I am calling the code:

ret = EncodeMp3(txtFile.Text, txtOutPut.Text, Val(cmbBitrate.Text),
SampleRate, Mode, AddressOf EnumEncoding)

And finally, here is the EnumEncoding procedure:

Public Function EnumEncoding(ByVal nStatus As Short) As Boolean

If pb1.Value <> nStatus Then
lblPercent.Text = nStatus & "%"
pb1.Value = nStatus
End If

If EncCancel Then
EnumEncoding = False
EncCancel = False
Else
EnumEncoding = True
End If

System.Windows.Forms.Application.DoEvents()
End Function

I keep getting a build error saying my delegates are not correct, but
i can't seem to figure out what I need to pass into them to be
correct.

Any ideas?
 
M

Mattias Sjögren

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal
lpszWavFile As String, ByVal lpszOutFile As String, ByVal Bitrate As
Integer, ByVal SampleRate As Integer, ByVal EncMode As EncodeMode,
ByRef lpCallback As EnumEncodingBoolDelegate) As Integer

lpCallback should probably be ByVal


ret = EncodeMp3(txtFile.Text, txtOutPut.Text, Val(cmbBitrate.Text),
SampleRate, Mode, AddressOf EnumEncoding)

And finally, here is the EnumEncoding procedure:

Public Function EnumEncoding(ByVal nStatus As Short) As Boolean [...]
I keep getting a build error saying my delegates are not correct,

None of the delegates you declared match the signature of the
EnumEncoding method.



Mattias
 
S

Scott

This is off the top of my head and I couldn't check it because I don't have
the mentioned DLL, but give this a shot...

Public Delegate Function myCallback(ByVal nStatus As Short) As Boolean

Public Function EnumEncoding(ByVal nStatus As Short) As Boolean
If pb1.Value <> nStatus Then
lblPercent.Text = nStatus & "%"
pb1.Value = nStatus
End If

If EncCancel Then
EnumEncoding = False
EncCancel = False
Else
EnumEncoding = True
End If

System.Windows.Forms.Application.DoEvents()
End Function

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" _
(ByVal lpszWavFile As String, ByVal lpszOutFile As String, _
ByVal Bitrate As Int32, ByVal SampleRate As Int32, _
ByVal EncMode As EncodeMode, ByVal lpCallback As myCallback) As Int32


And then call the "EncodeMp3" function using "AddressOf EnumEncoding" as the
last parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top