Jump to content
Sign in to follow this  
Greenhorn

captdll.dll in a Loop ?

Recommended Posts

Greenhorn

Hi Folks !

At first I wanna thank the Author/Creator of the captdll.dll, it's a great thing !

Now I have a problem by using it in a loop. :)

Please, can anybody tell me what's wrong with this code ???

$i = 1

While 1
    $PicName = "Screenshot_" & $i & ".jpg"
    DllCall("captdll.dll", "int", "CaptureScreen", "str", $PicName, "int", 85)
    Sleep(5000)
    $i = $i +1
    
WEnd

If I execute the Script there will be only one .jpg created and then the Script ends with Return Code 0, so no error is found !!! :)

Why is the loop executed only one time ???

If I put MsgBox in the code instead of DLLCall, the Box displays what I want to see: Screeshot_1.jpg, Screeshot_2.jpg, Screeshot_3.jpg...

Thanx a lot for your attention !

Greetz

Greenhorn

Share this post


Link to post
Share on other sites
The Kandie Man

This is why:

http://www.autoitscript.com/forum/index.ph...st&p=355320

This is a working version of the code you gave. I cleaned it up and added to it.

HotKeySet("{End}","Terminate")
Dim $h_DllCaptDLL = DllOpen("captdll.dll");Open it only once at the beginning and close it once at the end.  Not every time the while loops.
Dim $i = 1

While 1
    DllCall($h_DllCaptDLL, "int:cdecl", "CaptureScreen", "str", "Screenshot_" & $i & ".jpg", "int", 85)
    Sleep(5000)
    $i += 1
WEnd


;Exit helper functions
Func Terminate()
    Exit
EndFunc
Func OnAutoItExit()
DllClose($h_DllCaptDLL);closing the dll now that the script is exiting.
EndFunc

-The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites
poisonkiller

I ran your code and I got this error (I have latest captdll.dll and AutoIt v3.2.4.9):

Line 5 (File "C:\Documents and Settings\Admin\Scripts\New AutoIt v3 Script.au3"):

DllCall("captdll.dll", "int", "CaptureScreen", "str", $PicName, "int", 85)

Error: AutoIt has detected the stack has become corrupt.

Stack corruption typically occurs when either the wrong calling convention is used or when the function is called with the wrong number of arguments.

AutoIt supports the __stdcall (WINAPI) and __cdecl calling conventions. The __stdcall (WINAPI) convetion is used by default but __cdecl can be used instead. See the DllCall() documentation for details on changing the calling convention.

And this doesn't only come with your script, it comes with any script where I call "captdll.dll" with DllCall(). What's the fix of this?

EDIT: The Candie Man, why does DllCall second parameter have to be "int:cdecl"? In older versions of AutoIt it had to be only "int"...

Edited by poisonkiller

Share this post


Link to post
Share on other sites
Greenhorn

Billion thx Kandie Man !

I'll try it as soon as possible, but I must go to bed now (if I could sleep at this temperatures here in Hamburg...).

Tomorrow's hard work at my company.

C' ya...

Greetz

Greenhorn

Edit: thx a lot, too, poisonkiller !!!

But I've got none Error Message, not by Windows (xp) and not by AutoIt (also using 3.2.4.9)

Maybe it depends on TransformationPack 6, couldn't it ?

Edited by Greenhorn

Share this post


Link to post
Share on other sites
The Kandie Man

I ran your code and I got this error (I have latest captdll.dll and AutoIt v3.2.4.9):

Line 5 (File "C:\Documents and Settings\Admin\Scripts\New AutoIt v3 Script.au3"):
 
 DllCall("captdll.dll", "int", "CaptureScreen", "str", $PicName, "int", 85)
 
 Error: AutoIt has detected the stack has become corrupt.
 
 Stack corruption typically occurs when either the wrong calling convention is used or when the function is called with the wrong number of arguments.
 
 AutoIt supports the __stdcall (WINAPI) and __cdecl calling conventions. The __stdcall (WINAPI) convetion is used by default but __cdecl can be used instead. See the DllCall() documentation for details on changing the calling convention.

And this doesn't only come with your script, it comes with any script where I call "captdll.dll" with DllCall(). What's the fix of this?

EDIT: The Candie Man, why does DllCall second parameter have to be "int:cdecl"? In older versions of AutoIt it had to be only "int"...

This is a new behavior that has been implemented in the newer versions of AutoIt. This behavior assists people in debugging DLL calls by making the user implicitly declare that the dll they are using uses the STD calling convention or the CDECL calling convention. By default, AutoIt assumes that the DLL is using the STD calling conventions. When it doesn't use this convention, it hard crashes. Captdll.dll, written by Lazycat, uses the C Declared calling convention. As a result, AutoIt hard crashes when you do no implicitly instruct it to open the DLL with the correct calling convention.

- The Kandie Man ;-)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites
Greenhorn

Wooow, it works perfectly !!! I'm very delighted...

HotKeySet("{End}","Terminate")
Dim $h_DllCaptDLL = DllOpen("captdll.dll");Open it only once at the beginning and close it once at the end.  Not every time the while loops.
Dim $i = 1

While 1
    DllCall($h_DllCaptDLL, "int:cdecl", "CaptureScreen", "str", "Screenshot_" & $i & ".bmp", "int", -1)
    Sleep(5000)
    $i += 1
WEnd


;Exit helper functions
Func Terminate()
    Exit
EndFunc
Func OnAutoItExit()
DllClose($h_DllCaptDLL);closing the dll now that the script is exiting.
EndFunc

I couldn't say it enough times --> Thanks a lot for your the time you've spent !

Greetz

Greenhorn

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  

×