Jump to content

Stack Fault From Autoit Script


Recommended Posts

AutoItSetOption("TrayIconHide", 1)

HotKeySet("{F8}", "PicView") 
HotKeySet("{F7}", "PicViewBack")
HotKeySet("{F5}", "TerminateStream")

#include <file.au3>
Global $search, $file, $running, $winTarget, $c, $photos, $chkExt, $folderTarget, $back

; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------


;Start  waiting.
     Wait()

     
;Main wait function.     
Func Wait()
     FileDelete("C:\Windows\Temp\dir.txt")
     $back="no"
     $running="no"
While 1 
     Sleep(300000)
WEnd
EndFunc     


;Wait for next F7 or F8 keypress after the initial press.
Func WaitUpdate()
While 1
     Sleep(300000)     
WEnd
EndFunc     


;Search for target folder window and also get a list of JPG pictures from the folder when found.
Func PicView()
     $back="no" 
If $running="yes" Then UpdatePic()
     $winClass=StringStripCR(StringStripWs(StringLeft(WinGetClassList(""), "7"), "8"))
If $winClass <> "WorkerA" Then 
     WinMinimizeAll()
     MsgBox(0, "PicView 0.5", "Please maximize the target folder window and then click OK.")
     Send("!{TAB}")
     Sleep(200)
     $winClass=StringStripCR(StringStripWs(StringLeft(WinGetClassList(""), "7"), "8"))
EndIf
If $winClass = "WorkerA" Then 
     $winTarget=WinGetTitle("")  
Else
     MsgBox(0, "PicView 0.5", "Target window is not a valid folder.")
     Wait()
EndIf  
     $folderTarget=ControlGetText($winTarget, "", "Edit1")
     FileChangeDir($folderTarget)
     $search=FileFindFirstFile("*.jpg")     
If $search = -1 Then
     MsgBox(0, "PicView 0.5", "No JPEG photos found in current directory.")
     Wait()
Else 
     FileClose($search)
     RunWait(@Comspec & ' /c Dir /O:d /A:-d /B "' & $folderTarget & '" > %temp%\dir.txt', "", @SW_Hide)
If Not FileExists(@TempDir & "\dir.txt") Then MsgBox(0, "", "Errror")
     _FileReadToArray(@TempDir & "\dir.txt", $photos)
     $running="yes"
     UpdatePic()
EndIf     
EndFunc


;Display the next picture or previous picture.
Func UpdatePic()
If ProcessExists("PoloView.exe") Then 
     ProcessClose("PoloView.exe")  
EndIf
While 1
If $back="yes" Then
     $c=$c - 1
Else     
     $c=$c + 1
EndIf     
If $c > $photos[0] OR $c < 1 Then     
     SoundPlay ( "C:\Windows\Media\Chord.wav", 1)
     Wait()
EndIf     
     $file= $photos[$c]
     $chkExt=StringRight($file, "3") 
If $chkExt = "jpg" OR $chkExt = "JPG" Then ExitLoop
WEnd     
     Run("C:\Program Files\PoloView.exe " & $file)
     WaitUpdate()
EndFunc     
     
  
;Set $back="yes" so UpdatePic() will display the previous picture.
Func PicViewBack()
If $running="no" Then     
     SoundPlay ( "C:\Windows\Media\Chord.wav", 1)
     Wait()
EndIf     
     $back="yes"
     UpdatePic()
EndFunc       


;Quit displaying pictures.
Func TerminateStream()
If ProcessExists("PoloView.exe") Then 
     ProcessClose("PoloView.exe")     
EndIf     
     Wait()
EndFunc

The purpose of this script is to run in the background, waiting for a HotKey press. When the HotKey is pressed look for an open Windows Explorer window containing *.jpg pictures. It then displays them sorted by date one by one with each HotKey press. It can also page backwards through the list of pictures.

Sort of like the Windows XP Image viewer, perhaps???

(My Operating Sys is Windows 98SE)

I've tried using PhotoSuite to display the photos and now I'm trying PoloView.exe, but either way I come up with the results below... ... I've also tried assigning different HotKeys... ... I've tried running a compiled copy of the script or a non-compiled copy... ... .......................

The script works fine, up to about 25 pictures, then a Windows Illegal Operation box pops up with this error:

PICVIEW caused a stack fault in module PICVIEW.EXE at 017f:00417ef7.

Registers:

EAX=0000409c CS=017f EIP=00417ef7 EFLGS=00010206

EBX=0058be14 SS=0187 ESP=00583b6c EBP=00583b74

ECX=00581b74 DS=0187 ESI=00431c20 FS=36c7

EDX=00000000 ES=0187 EDI=0058bbc8 GS=0000

Bytes at CS:EIP:

85 01 3d 00 10 00 00 73 ec 2b c8 8b c4 85 01 8b

Stack dump:

00431c20 0040e2ea 0058bba8 00403263 00000011 0058bbc8 00000001 00000001 00000010 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Thanks for any help,

Kendall

Edited by Larry
Link to comment
Share on other sites

One thing I see, you don't need to call Wait() all the time. Just start an infinite loop something like:

While 1
    Sleep(250)
WEnd

That will need a hotkey to exit the script, of course.

Alternatively, you can make the loop watch for the closing of PoloView.exe. Then the hotkey isn't necessary.

I don't know if this is related to your problem or not, but it will definitly cause a problem at some point, I'm sure.

The hotkey doesn't cause the initial While loop to exit or anything. It just executes the hotkey callback at the first opportunity (After the end of a sleep or other blocking function). All those calls to Wait and WaitUpdate are needless.

Link to comment
Share on other sites

Thanks for the replies.

@Valik: You're right. I have a lot to learn. I made some of your suggested changes, but I didn't fully test the script at this point. Thank-you.

@CyberSlug: PoloView probably didn't have anything to do with my problem. But it does seem to have another bug when displaying pictures. I downloaded IRFan to check out sometime.

@Larry: I should have put the code tags around my script in my first post. Sorry about that and thanks for editing it.

Kendall

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...