写程序时发现该函数不支持目录名含有空格的文件播放
Public 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
result = mciSendString("Play F:\aaa\tada.wav", returnStr, 
128, 0)
执行该播放wav语句正常
若改为
result = mciSendString("Play F:\aa a\tada.wav", returnStr, 
128, 0)
就不出声了。
别人回答我原因如下
在command line中空格代表新的参数,所以它将F:\aa看作
一个参数,将a\tada.wav看作另一个参数。解决方法是用双引号将路径围上,如:result = mciSendString("Play ""F:\aa a\tada.wav""", returnStr, 128, 0)
测试通过,但时如果使用相对路径
result = mciSendString("Play " & Application.StartupPath 
& "\Goodbye.wav", returnStr, 128, 0)
如果相对路径正好是一个含有空格的长路径,就又不出声了
用加双引号也无法解决。
后来在CSDN上发现介绍说要将长路经转换成短路经,使用GetShortPathName()函数
Public Declare Function GetShortPathName Lib "kernel32" 
Alias "GetShortPathNameA" (ByVal lpszLongPath As String, 
ByVal lpszShortPath As String, ByVal cchBuffer As Integer) 
As Integer
调试时发现
这个函数的LpszLongPath 给他一个字符串他没反应,总是传递不了
参数值
那位高手能解决这个问题阿?
最好能将调试好的代码贴出来!这个问题在微软新闻组里也贴了,至今还未解决。
http://communities.microsoft.com/newsgroups/default.asp?ICP=chinacommunity&sLCID=cn&NewsGroup=microsoft.public.cn.dotnet.languages.vbhttp://www.csdn.net/Develop/Article/15/15323.shtm
这是CSDN上的MciSendString的介绍

解决方案 »

  1.   

    给你个例子:
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    Public Function GetShortPath(strFileName As String) As String
        
        Dim lngRes As Long, strPath As String
        'Create a buffer
        strPath = String$(165, 0)'这句是关键
        'retrieve the short pathname
        lngRes = GetShortPathName(strFileName, strPath, 164)
        'remove all unnecessary chr$(0)'s
        GetShortPath = Left$(strPath, lngRes)
    End Function
    Private Sub Form_Load()
        MsgBox GetShortPath("c:\Program Files\")
    End Sub
    调试时发现
    这个函数的LpszLongPath 给他一个字符串他没反应,总是传递不了
    参数值关键是要先给字串一个足够大的缓冲区
      

  2.   

    我给了255的缓冲,足够了。
    另外我的环境是VB.net
    你贴的代码是VB6的
    里面恒多地方在VB.net里是非法的如
    strPath = String$(165, 0)