MCI Commands - Updating VB6 code to VB.NET

  • Thread starter Thread starter The old Curmudgeon
  • Start date Start date
T

The old Curmudgeon

Guest
The code I am using is from a VB6 Class modal. It works fine in that old project. I am now converting to VB.NET using the Visual Studio 2017 IDE. I am frustrated as I can not get the connection to work and do not know why, and I don't know how to read the error code that is returned as none of the MCI commands see to work. Any suggestions are welcome. Here is the relevant code from a class module in the project:

Public Class MMedia

Friend Shared msAlias As String 'Local name of the multimedia resource
Friend Shared msFilename As String 'Holds the filename
Friend Shared msLength As Single 'length of the filename
Friend Shared msPosition As Single 'current position in file
Friend Shared msStatus As String 'current status as a string
Friend Shared mbWait As Boolean 'Determines if VB should wait until play is complete before returning.

'------------ API DECLARATIONS ---------------------------------------------
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String,
ByVal uReturmsLength As Long, ByVal hwndCallback As Long) As Long

Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" _
(ByVal fdwError As Long, ByVal lpszErrorText As String, ByVal cchErrorText As Long) As Boolean '

Private Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" _
(ByVal lpszDevice As String) As Integer

Private Declare Function midiOutGetNumDevs Lib "winmm.dll" () As Integer

Public Sub mmOpen(ByVal sTheFile As String)
Dim nReturn As Long
Dim sType As String
Dim sMessage As String = ""
Dim sError As String
Dim iDeviceID As Integer

msAlias = Alb.MidiSource 'See notes

' Determine the type of file from the file extension
Select Case Strings.UCase(Strings.Right(sTheFile, 3))
Case "WAV"
sType = "Waveaudio"
Case "AVI"
sType = "AviVideo"
Case "MID"
sType = "Sequencer"
Case Else 'not known
Exit Sub
End Select

' If the name contains a space we have to enclose it in quotes
If Strings.InStr(sTheFile, " ") Then sTheFile = Chr(34) & sTheFile & Chr(34)
nReturn = mciSendString("Open " & sTheFile & " ALIAS " & msAlias _
& " TYPE " & sType & " wait", "", 0, 0)

sError = mciGetErrorString(nReturn, sMessage, 128)
sError = dhMCIError(nReturn)
If sMessage = "" Then sMessage = "Error unknown"
If nReturn = 0 Then sMessage = "" 'add ErrorTrap


'Get device ID
iDeviceID = mciGetDeviceID(msAlias) ' ############ Tells what current device ID# is
If iDeviceID = 0 Then msAlias = "" ' File did not open
Console.WriteLine("Midi Device " & iDeviceID, " opened as " & msAlias)


mdiAlberta.lstDetails.Items.Add("Midi Player open on Device # " & iDeviceID & " = " & msAlias)
Console.WriteLine(" Error code = " & nReturn & " Msg: " & sError)

End Sub

The "sTheFile" string is the file that is opened using the OpenFileDialog method. In this case it will look like:

"C:\Users\Curmudgeon\Documents\Midi Song Files\Boogie Woogie Piano Track.mid"

The midi file is decoded in the project and then I attempt to open the file in the MMplayer. This all worked fine in VB6. The nReturn result when I attempt to open the player is a numerical string. Example: 66991044457136397

I don't know how to read that code and I do not have any luck using the sError = mciGetErrorString(nReturn, sMessage, 128)

method. Can anyone help me here? Thanks in advance.

Continue reading...
 
Back
Top