PRB: Multimedia API Calls May Fail with Long File Names
ID: Q191089
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
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
- Create a new Standard EXE project. Form1 is created by default.
- 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.
- Place a CommonDialog control and two CommandButtons onto Form1.
- 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
- Save and run the project.
- 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.
- Follow the comments in Command1_Click, then repeat step 6. The function
should now succeed and return a zero.
Additional query words:
kbVBp kbdsd kbDSupport kbVBp400 kbVBp500 kbVBp600 kbAPI kbmm kbds
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbprb
|