PRB: Multimedia API Calls May Fail with Long File Names (191089)



The information in this article applies to:

  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q191089

SYMPTOMS

Multimedia API calls such as "mciSendString" may fail when you pass a file path or file name that uses long file names.

RESOLUTION

Make sure you use a standard 8.3 path and file name. Or, wrap the path and file name in quotes.

STATUS

This behavior is by design.

MORE INFORMATION

When using multimedia API calls to play multimedia files, the API call may fail if the path or file name in the command string has embedded spaces. The following example uses the mciSendString API to demonstrate this.

Steps to Reproduce Behavior

  1. Create a new Standard EXE project. Form1 is created by default.
  2. Using the Projects menu click Components to bring up the Components dialog box. On the Controls tab select "Microsoft Common Dialog Control" and click OK.
  3. Place a CommonDialog control and two CommandButtons onto Form1.
  4. Add the following code to Form1's module:
          Private Declare Function mciSendString Lib "winmm.dll" Alias _
           "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
           lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
           hwndCallback As Long) As Long
    
          Private Sub Command1_Click()
            CommonDialog1.ShowOpen
            Debug.Print CommonDialog1.filename
            Debug.Print mciSendString( _
              "open " & CommonDialog1.filename & " alias testfile", 0&, 0, 0)
            ' To work around the long file name limitation use the next line
            ' instead of the previous line, which adds quotes around the path
            ' and file name.
            'Debug.Print mciSendString( _
              "open " & """" & CommonDialog1.filename & """" _
             & " alias testfile", 0&, 0, 0)
    
            Debug.Print mciSendString("play testfile wait", 0&, 0, 0)
          End Sub
    
          Private Sub Command2_Click()
            Debug.Print mciSendString("close testfile", 0&, 0, 0)
          End Sub
    
          Private Sub Form_Load()
            Command1.Caption = "Open and Run"
            Command2.Caption = "Close MDI file"
          End Sub
    						
  5. Save and run the project.
  6. Click on the Open button and select an .avi file that has a long file or path name. The mciSendString call will return an error. You will see this because the return value will be a non-zero.
  7. Follow the comments in Command1_Click, then repeat step 6. The function should now succeed and return a zero.

Modification Type:MajorLast Reviewed:5/13/2003
Keywords:kbprb KB191089