MciSendString

G

Guest

Could anyone tell me what am i doing bad?

When i use the "MciSendString" always returns a big number instead 0 : What
it says that there is an error, and so don't play the sound.

Then direction of the sound .wav it's ok

I must not use any .ocx.

Could anyone compile it and tell me what it's wrong?

This is the code:

Public Class Form1
Inherits System.Windows.Forms.Form

Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal
uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function mciGetErrorString Lib "winmm.dll" Alias
"mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String,
ByVal uLength As Long) As Long

Private Direccion As String
Private cadena As String

Sub MandarMensaje(ByVal mensaje As String)
Dim resultado As Long

cadena = Space(255)
resultado = mciSendString(mensaje, cadena, Len(cadena), 0)
BuscarError(resultado)
End Sub


Sub BuscarError(ByVal número As Long)
Dim errorBE As String

errorBE = Space(255)
mciGetErrorString(número, errorBE, 255)
Label1.Text = errorBE
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog
openFileDialog1.InitialDirectory = CurDir() & "\Sonidos"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then
Direccion = openFileDialog1.FileName

TextBox1.Text = Direccion

MandarMensaje("close archivowav")
MandarMensaje("open " & Direccion & " type waveaudio alias
archivowav")
MandarMensaje("set archivowav time format milliseconds")
MandarMensaje("status archivowav length")
If Val(Trim(cadena)) <> 0 Then ' Si dicho tiempo es distinto de 0
ProgressBar1.Minimum = 1
ProgressBar1.Maximum = Val(cadena)
ProgressBar1.Value = 1
Slider1.Minimum = 1
Slider1.Maximum = Val(cadena)
Slider1.Value = 1
End If
Label2.Text = Format(Val(cadena), "MM:SS")
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Timer1.Enabled = True
MandarMensaje("play archivowav from 0")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
MandarMensaje("status archivowav position")
ProgressBar1.Value = Val(cadena)
Slider1.Value = Val(cadena)
Label2.Text = Format(ProgressBar1.Maximum - Val(cadena), "MM:SS")
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
MandarMensaje("stop archivowav")
Timer1.Enabled = False
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If Button4.Text = "Pausa" Then
MandarMensaje("pause archivowav")
Button4.Text = "Continuar"
Else
MandarMensaje("resume archivowav")
Button4.Text = "Pausa"
End If
End Sub
End Class


Thanks everyone
 
H

Herfried K. Wagner [MVP]

César said:
When i use the "MciSendString" always returns a big number instead 0 :
What
it says that there is an error, and so don't play the sound.
[...]
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA"
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal
uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function mciGetErrorString Lib "winmm.dll" Alias
"mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String,
ByVal uLength As Long) As Long

Your declarations are wrong. Use these instead (untested):

\\\
Private Declare Auto Function mciSendString Lib "winmm.dll" ( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As UInt32, _
ByVal hwndCallback As IntPtr _
) As Int32

Private Declare Auto Function mciGetErrorString Lib "winmm.dll" ( _
ByVal dwError As Int32, _
ByVal lpstrBuffer As String, _
ByVal uLength As UInt32 _
) As Int32
///
 

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