Jump to content

function _mciSendString() of Winmm.dll does not accept directory path with space.


Go to solution Solved by Belini,

Recommended Posts

I can't play videos using winmm.dll if there is space in the directory path and I can't solve this, in the research I did I found people with the same problem and the solution they gave was to put the path in quotes but in Autoit it didn't work, is there anything Another way to pass paths with space to the _mciSendString() function that works in Autoit?

Similar problem to mine:   https://stackoverflow.com/questions/1148022/mcisendstring-cannot-save-to-directory-path

My attempts:

Func _Video_Open($sFile, $hWnd, $iX, $iY, $iH, $iW, $sDevice = "")
        Local $sVID, $gId, $iRet, $sDT = ""
        
        ;$sFile = '"' & $sFile & '"' ; <============================ It didn't work with space in the name 
        ;$sFile = chr(32) & $sFile & chr(32) ; <===================== It didn't work with space in the name
        
        ;I need another way to pass the path with space to open the videos ; <============================ My problem
        
        If Not FileExists($sFile) Then Return SetError(1, 0, "")
        If Not IsHWnd($hWnd) Then Return SetError(2, 0, "")
        If $sDevice <> "" Then
                If Not _mciDeviceExists($sDevice) Then Return SetError(3, 0, "")
                $sDT = " type " & $sDevice
        EndIf
        $gId = Dec(StringTrimLeft($hWnd, 2))
        $sVID = _RandomStr()
        $iRet = _mciSendString("open " & FileGetShortName($sFile) & " alias " & $sVID & $sDT)
        If $iRet <> 0 Then Return SetError(4, 0, "")
        $iRet = _mciSendString("window " & $sVID & " handle " & $gId)
        If $iRet <> 0 Then
                _mciSendString("close " & $sVID)
                Return SetError(5, 0, "")
        EndIf
        $iRet = _mciSendString("put " & $sVID & " destination at " & $iX & " " & $iY & " " & $iH & " " & $iW)
        If $iRet <> 0 Then
                _mciSendString("close " & $sVID)
                Return SetError(6, 0, "")
        EndIf
        Return SetError(0, 0, $sVID)
EndFunc   ;==>_Video_Open

Func _mciSendString($string, $iLen = 0)
        Local $iRet 
        $iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $string, "str", "", "long", $iLen, "long", 0)
        If Not @error Then Return $iRet[2]
EndFunc   ;==>_mciSendString

 

Edited by Belini
Link to comment
Share on other sites

27 minutes ago, Belini said:

the solution they gave was to put the path in quotes but in Autoit it didn't work

I wonder how you did that.

Func _Video_Open($sFile, $hWnd, $iX, $iY, $iH, $iW, $sDevice = "")
        Local $sVID, $gId, $iRet, $sDT = ""

        ;$sFile = '"' & $sFile & '"' ; <============================ It didn't work with space in the name
        ;$sFile = chr(32) & $sFile & chr(32) ; <===================== It didn't work with space in the name

        ;I need another way to pass the path with space to open the videos ; <============================ My problem

        If Not FileExists($sFile) Then Return SetError(1, 0, "")
        If Not IsHWnd($hWnd) Then Return SetError(2, 0, "")
        If $sDevice <> "" Then
                If Not _mciDeviceExists($sDevice) Then Return SetError(3, 0, "")
                $sDT = " type " & $sDevice
        EndIf
        $gId = Dec(StringTrimLeft($hWnd, 2))
        $sVID = _RandomStr()
        $iRet = _mciSendString('open "' & FileGetShortName($sFile) & '" alias ' & $sVID & $sDT)    ; <<<--- this line is modified
        If $iRet <> 0 Then Return SetError(4, 0, "")
        $iRet = _mciSendString("window " & $sVID & " handle " & $gId)
        If $iRet <> 0 Then
                _mciSendString("close " & $sVID)
                Return SetError(5, 0, "")
        EndIf
        $iRet = _mciSendString("put " & $sVID & " destination at " & $iX & " " & $iY & " " & $iH & " " & $iW)
        If $iRet <> 0 Then
                _mciSendString("close " & $sVID)
                Return SetError(6, 0, "")
        EndIf
        Return SetError(0, 0, $sVID)
EndFunc

Tested with spaces in path and file name and works properly.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

34 minutes ago, Belini said:

... is there anything Another way to pass paths with space to the _mciSendString() function that works in Autoit?

you could try it like this...

$sFile = FileGetShortName($sFile)
Edited by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

@Andreik just putting quotes I had already tried and it didn't work

@Gianni using FileGetShortName() I had also tried and it didn't work

Link to comment
Share on other sites

  • Solution

I found the cause of the problem, it doesn't work if you use quotation marks if you are using FileGetShortName() and in the end using quotation marks was the solution but it has to be in the full path and not in the shortest path.

$iRet = _mciSendString("open " & FileGetShortName($sFile) & " alias " & $sVID & $sDT); Does not work
; exchanged for
$iRet = _mciSendString("open " & '"' & $sFile & '"' & " alias " & $sVID & $sDT); now everything works

Thanks @Andreik and @Gianni for trying to help

EDITED: I think it has to do with the version of Winmm.dll because I always used FileGetShortName() and it always worked and I never needed to use quotes for it to work but in this version it only works with quotes in the full path and without using FileGetShortName()

Edited by Belini
Link to comment
Share on other sites

Further to @Andreik's suggestion, you can use two double quotes around $sFile.
In zPlayer, I used the following code to open audio or video files. 
 

mciSendString("open """ & $sFile & """ alias myMedia type MPEGVideo wait style popup parent " & $iGui)

 

Edited by CYCho
Link to comment
Share on other sites

@CYCho the quotation marks really solve the problem, but if you use FileGetShortName() even placing quotation marks does not work in this version of winmm.dll which caused the problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...