These seems to be catching error and working in VB10 / .Net4 for me.
Code: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 dwError As Integer, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer Dim ErrCode As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim RetStr As String = Space(1024) ErrCode = mciSendString("open new type waveaudio alias RecWavFile", RetStr, 1024, 0) If ErrCode = 0 Then ErrCode = mciSendString("set RecWavFile channels 2", RetStr, 1024, 0) ' Stereo Or Mono Sound If ErrCode = 0 Then ErrCode = mciSendString("set RecWavFile samplespersec 44100", RetStr, 1024, 0) ' Khz Rate If ErrCode = 0 Then ' Make it error...... bitspersample = 6 <<< (should be 8 or 16?) ErrCode = mciSendString("set RecWavFile bitspersample 6", RetStr, 1024, 0) ' Sound Sample Rate (Bits) If ErrCode = 0 Then ErrCode = mciSendString("record RecWavFile", RetStr, 1024, 0) End If End If End If End If If ErrCode <> 0 Then MessageBox.Show(GetMCIErrorString(ErrCode)) End Sub Private Function GetMCIErrorString(ByVal ErrorCode As Integer) As String 'create a buffer GetMCIErrorString = Space(1024) 'retrieve the error string mciGetErrorString(ErrorCode, GetMCIErrorString, Len(GetMCIErrorString)) 'strip off the trailing spaces GetMCIErrorString = Trim(GetMCIErrorString) End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' // stop and save to file // Dim RetStr As String = Space(1024) 'Will show error here if path/folder doesn't exist ErrCode = mciSendString("save RecWavFile D:\TEST\RecWavFile.wav", RetStr, 1024, 0) If ErrCode <> 0 Then MessageBox.Show(GetMCIErrorString(ErrCode)) ErrCode = mciSendString("close RecWavFile", RetStr, 1024, 0) If ErrCode <> 0 Then MessageBox.Show(GetMCIErrorString(ErrCode)) End Sub End Class




Reply With Quote