Public Class Form1 Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal fdwError As Integer, ByVal lpszErrorText As String, ByVal cchErrorText As Integer) As Integer Public Sub SendString(cmdString As String) Dim result As Integer = mciSendString(cmdString, "", 0, 0) If result <> 0 Then 'エラーメッセージを取得して表示します。 Dim ErrorMessage As String = GetErrorString(result) MsgBox(ErrorMessage, MsgBoxStyle.Exclamation, "Error " & result) End If End Sub '■再生 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fileName As String = "C:\vb\test.mpg" SendString("open """ & fileName & """ alias MyMovie") SendString("window MyMovie handle " & PictureBox1.Handle.ToString) SendString("play MyMovie") End Sub '■停止 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click SendString("close MyMovie") End Sub '■GetErrorString ''' <summary>mciSendString関数の戻り値からエラーメッセージを取得します。</summary> ''' <param name="APIResult">mciSendString関数の戻り値。エラーコード。</param> ''' <returns>APIResultに対応するエラーメッセージを返します。</returns> Private Function GetErrorString(ByVal apiResult As Integer) As String Dim buffer As String = New String(Chr(0), 255) Dim errorMessage As String Call mciGetErrorString(apiResult, buffer, Len(buffer)) errorMessage = Replace(buffer, Chr(0), "") Return errorMessage End Function End Class