Results 1 to 2 of 2

Thread: mciSendString save wave file problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    mciSendString save wave file problem

    ello,

    VS 2008 SP1

    I have a created a small application that records and plays audio. However, my application needs to save the wave file to the application data directory on the users computer.

    The mciSendString takes a C style string as a parameter and has to be in 8.3 format. However, my problem is I can't get it to save. And what is strange is sometime it does and sometimes it doesn't. However, most of the time it failes. However, if I save directly to the C drive it works first time everything. I have used 3 different methods that I have coded below.

    The error number that I get when it fails is 286."The file was not saved. Make sure your system has sufficient disk space or has an intact network connection"

    Many thanks for any suggestions,

    <DllImport("winmm.dll", CharSet := CharSet.Auto)> _
    Private Shared Function mciSendString(<MarshalAs(UnmanagedType.LPTStr)> ByVal command As String, ByVal returnValue As StringBuilder, ByVal returnLength As Integer, ByVal winHandle As IntPtr) As UInteger
    End Function

    Code:
    <DllImport("winmm.dll", CharSet := CharSet.Auto)> _
    Private Shared Function mciGetErrorString(ByVal errorCode As UInteger, ByVal errorText As StringBuilder, ByVal errorTextSize As Integer) As Integer
    End Function
    
    <DllImport("Kernel32.dll", CharSet := CharSet.Auto)> _
    Private Shared Function GetShortPathName(<MarshalAs(UnmanagedType.LPTStr)> ByVal longPath As String, <MarshalAs(UnmanagedType.LPTStr)> ByVal shortPath As StringBuilder, ByVal length As Integer) As Integer
    End Function
    Code:
     'Stop recording
    Private Sub StopRecording()
        ' Save recorded voice
        Dim shortPath As String = Me.shortPathName()
        Dim formatShortPath As String = String.Format("save recsound ""{0}""", shortPath)
        Dim result As UInteger = 0
        Dim errorTest As New StringBuilder(256)
        
        ' C:\DOCUME~1\Steve\APPLIC~1\Test.wav
        ' Fails
        result = mciSendString(String.Format("{0}", formatShortPath), Nothing, 0, IntPtr.Zero)
        mciGetErrorString(result, errorTest, errorTest.Length)
        
        ' command line convention - fails
        result = mciSendString("save recsound ""C:\DOCUME~1\Steve\APPLIC~1\Test.wav""", Nothing, 0, IntPtr.Zero)
        mciGetErrorString(result, errorTest, errorTest.Length)
        
        ' 8.3 short format - fails
        result = mciSendString("save recsound C:\DOCUME~1\Steve\APPLIC~1\Test.wav", Nothing, 0, IntPtr.Zero)
        mciGetErrorString(result, errorTest, errorTest.Length)
        
        ' Save to C drive works everytime.
        result = mciSendString("save recsound C:\Test.wav", Nothing, 0, IntPtr.Zero)
        mciGetErrorString(result, errorTest, errorTest.Length)
        
        mciSendString("close recsound ", Nothing, 0, IntPtr.Zero)
    End Sub

    Code:
    ' Get the short path name so that the mciSendString can save the recorded wave file
    Private Function shortPathName() As String
        Dim shortPath As String = String.Empty
        Dim length As Long = 0
        Dim buffer As New StringBuilder(256)
        
        ' Get the length of the path 
        length = GetShortPathName(Me.saveRecordingPath, buffer, 256)
        
        shortPath = buffer.ToString()
        
        Return shortPath
    End Function
    steve

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: mciSendString save wave file problem

    have a look at this thread. it might help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width