<System.Runtime.InteropServices.DllImport("winmm.dll")> Shared Function _
mciSendString(ByVal lpstrCommand As String, ByVal lpstrReturnString As _
String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As _
Integer
End Function
' helper routine; executes a MCI command
' commandString is the command to execute
' deviceAlreadyOpened must be set to true if the caller has already opened the
' device
Sub ExecuteMCICommand(ByVal commandString As String, ByVal deviceAlreadyOpened _
As Boolean)
Dim returnCode As Integer = mciSendString(commandString, vbNullString, 0, 0)
' if the return code is not 0, an error occurred
If returnCode <> 0 Then
' close the device if necessary
If deviceAlreadyOpened Then
commandString = "close AVIFile"
mciSendString(commandString, vbNullString, 0, 0)
End If
' throw a custom exception
Throw New MCICommandException(returnCode)
End If
End Sub
' helper custom exception
' motes: requires the GetMCIErrorString function
Class MCICommandException
Inherits Exception
Public Sub New(ByVal errorCode As Integer)
MyBase.New(GetMCIErrorString(errorCode))
End Sub
End Class