Sign in to follow this  
Followers 0
zend

Help - While() Bufferoverflow :)

5 posts in this topic

Hello,

I am new with AutoIt, and i am trying to build a script that:

Runs in a loop, to check if the window "Out Of Office Turned On" pops out and then anwers NO to this window.

The problem: The script takes up more and more memory over time. This will keep on going until it crashes with a bufferoverflow.

I did some google of my own, but still cant fix it. http://www.autoitscript.com/forum/lofiversion/index.php?t299.html

What am i doing wrong?

CODE
; ; Press Esc to terminate script, Pause/Break to "pause"

HotKeySet("{ESC}", "Terminate")

HotKeySet("^q", "loop1") ;Ctrl-q

$var = 0

;;;; Body of program ;;;;

While 1

Sleep(1)

WEnd

;;;;;;;;

Func Terminate()

Exit 0

EndFunc

Func Sl33p()

Sleep(1000000000)

loop1()

EndFunc

Func loop1()

While WinExists("Out Of Office Turned On") = 0

Sl33p()

WEnd

While WinExists("Out Of Office Turned On") = 1

WinActivate("Out Of Office Turned On")

WinWaitActive("Out Of Office Turned On")

ControlFocus("Out Of Office Turned On", "", "Button2")

ControlClick("Out Of Office Turned On", "", "Button2")

Sl33p()

WEnd

EndFunc

You would really help me out, and thanks in advance.

Kind regards,

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think a simple solution is this:

; ; Press Esc to terminate script, Pause/Break to "pause"
HotKeySet("{ESC}", "Terminate")
$var = 0

While 1
    Sleep(1000)
    If WinExists("Out Of Office Turned On") = 1 Then
        WinActivate("Out Of Office Turned On")
        WinWaitActive("Out Of Office Turned On")
        ControlClick("Out Of Office Turned On", "", "Button2")
    EndIf
WEnd

Func Terminate()
    Exit 0
EndFunc

The code runs singlethreaded, so the code sets your hotkey's, variable and then goes to the While 1 - WEnd loop.

In this loop you sleep for one millisecond and then proceed this loop.

You problem lies there. You have no way out of that very fast looping loop.

My code sleeps for one second and then looks for you window.

Edit: Lol, stupid typo in the WinExists...

And ControlFocus is not needed if you ControlClick it. :P

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

Allright, that was the exact problem i was trying to dodge, but have failed.

Thanks for the help and i am testing it now. I will see how its runs over night.

Anyway, alot thanks for the help.

Kind regards,

Share this post


Link to post
Share on other sites

Ok tested it and it works.

Thanks alot for helping me out now, and learning me something for future times :P

Share this post


Link to post
Share on other sites

In this loop you sleep for one millisecond and then proceed this loop.

You are wrong on that, it will actually be 10 ms. If you run Sleep() with 1-9 then it will automatically be 10.

Share this post


Link to post
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
Sign in to follow this  
Followers 0