Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Advanced
May 12, 2003

ExecuteMCICommand - Executing a MCI command

<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
Alberto Falossi
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap