Problem with "FileMenu for Media files.mnw"

Started by George Vagenas, September 23, 2014, 04:58:39 PM

Previous topic - Next topic

George Vagenas

This code runs fine as a menu item in Popmenu or in a file run from Popmenu.
Code (winbatch) Select
      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) Select
#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) Select
#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) Select
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) Select
Dir = wingetactive() which is changed in "FileMenu for Media files.mnw" to
Code (winbatch) Select
Dir = WinName()
Is there a fix for this?  I'd prefer to have this script run from the Explorer context menu.
Thanks

George

td

Our friends at MSFT appear to be playing cute with dll handles in the shell.  Try the following instead:

Code (winbatch) Select

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

Thanks

George