Author Topic: Problem with "FileMenu for Media files.mnw"  (Read 2332 times)

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Problem with "FileMenu for Media files.mnw"
« on: September 23, 2014, 04:58:39 pm »
This code runs fine as a menu item in Popmenu or in a file run from Popmenu.
Code: Winbatch
      call('Array.udl', 'udfArrQuickRSort,udfArray2List')      ; Load UDFs.
      windowontop('', @true)
      Dir = wingetactive()
      pause(`DEBUG PAUSE`, strCat(`Dir = `, Dir))   ;***DEBUG LINE***
      dirchange(Dir)
      fList = fileitemize('*.*')
      pause(`DEBUG PAUSE`, strCat(`fList = `, fList))   ;***DEBUG LINE***
      Ary = arrayize(fList, @tab)
      SortedAry = udfArrQuickRSort(Ary)
      fList = udfArray2List(SortedAry, @tab)
      Cnts = itemcount(fList, @tab)
      for Cnt = 1 to Cnts
         File = itemextract(Cnt, fList, @tab)
         if !isdefined(NewTime) then NewTime = timeymdhms()
         NewTime = TimeAdd(NewTime, "0000:00:00:00:01:00")
         filetimeset(File, NewTime)
      next ;Cnt  
 
But when run as a menu item in "FileMenu for Media files.mnw" it gives an error.  The error occurs in this function
Code: Winbatch
#DefineFunction udfArrQRSort(Array,left,right,hShlwapi)
   pause(`DEBUG PAUSE`, strCat(`hShlwapi = `, hShlwapi))   ;***DEBUG LINE***
   If (left<right)
      pivot = Array[(left + right) / 2]
      i = left
      k = right
      While(i<=k)
         While DllCall(hShlwapi,long:"StrCmpLogicalW", lpwstr:Array[i], lpwstr:pivot) < 0 ;(Array[i]
            i = i + 1
         EndWhile
         While DllCall(hShlwapi,long:"StrCmpLogicalW", lpwstr:pivot, lpwstr:Array[k]) < 0 ;(pivot
            k = k - 1
         EndWhile
         If (i<=k)
            A = Array[i]
            Array[i] = Array[k]
            Array[k] = A
            i = i + 1
            k = k - 1
         EndIf
      EndWhile
      ; udfArrQRSort(Array,left,k,hShlwapi)
      ; udfArrQRSort(Array,i,right,hShlwapi)
   EndIf
   Return(Array)
#EndFunction
 
which is called from this function
Code: Winbatch
#DefineFunction udfArrQuickRSort(Array) ; recursive
   call('Array.udl', 'udfArrQRSort')
   If (VarType(Array)<>256) Then Return(Array)
   If (ArrInfo(Array,0)>1) Then Return(Array)
   arrmax = ArrInfo(Array,1) - 1
   If (arrmax<0) Then Return(Array)
   hShlwapi = DllLoad("Shlwapi")
   udfArrQRSort(Array,0,arrmax,hShlwapi)
   DllFree(hShlwapi)
   Return(Array)
#EndFunction
 
Both functions are from the Tech Database, I inserted the Pause lines to verify the parameters being passed in the scripts.  When run from "FileMenu for Media files.mnw" the handle "hShlwapi" has a negative value and this line
Code: Winbatch
DllCall(hShlwapi,long:"StrCmpLogicalW", lpwstr:Array[i], lpwstr:pivot) < 0 ;(Array[i]
fails with error 1301: DllCall: Bad Entrypoint name.  the only difference between the scripts is this line
Code: Winbatch
Dir = wingetactive()
which is changed in "FileMenu for Media files.mnw" to
Code: Winbatch
Dir = WinName()
Is there a fix for this?  I'd prefer to have this script run from the Explorer context menu.
Thanks

George

td

  • Tech Support
  • *****
  • Posts: 3210
    • WinBatch
Re: Problem with "FileMenu for Media files.mnw"
« Reply #1 on: September 24, 2014, 09:30:58 am »
Our friends at MSFT appear to be playing cute with dll handles in the shell.  Try the following instead:

Code: Winbatch
DllCall("Shlwapi.dll",long:"StrCmpLogicalW", lpwstr:Array[i], lpwstr:pivot) < 0
 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Re: Problem with "FileMenu for Media files.mnw"
« Reply #2 on: September 24, 2014, 12:46:18 pm »
Works fine now!
Thanks

George