Jump to content

DllCallbackRegister with non freezing GUI (Volatile) Example


GtaSpider
 Share

Recommended Posts

The name of this keyword is "volatile" (not capitalized). Current AutoIt documentation is wrong.

I'm not sure why would someone change the documentation for this keyword, if it's written by its author. Regardless of AutoIt's case-inesitivity, documentation should give correct casing.

Anyway, it's not "Volatile".

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Trancexx, all AutoIt functions and keywords are (AFAIK) case-insensitive. Therefore, msgbox(...) and MsgBox(...) both work exactly the same. As a matter of fact, if someone wanted to write their code AS THOUGH THEY ARE SHOUTING IT WOULD WORK JUST THE SAME. Actually it's quite funny to see what AutoIt does internally with the names of functions, when you try this code.

$funcname = MsgBox
MsgBox(0,"",FuncName($funcname))
Who else would I be?
Link to comment
Share on other sites

If trancexx insists on this point there must be a reason behind.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I decided to give the MoveFileWithProgress function a shot.  It claims that the operation completed successfully.  I have my doubts because the callback never fires and the file is still in its original location.

EDIT: Ok, the file moved!  However, the callback was not executed.  =(

Edit: Probably has something to do with this line:

Local Const $progress_callback = DllCallbackRegister($progress_routine, "dword", "dword;dword;dword;dword;dword;dword;handle;handle;ptr;")

The first four DWORDs are supposed to be LARGE_INTEGERs, but I don't know what to substitute in place of them.

Edit: Think I just figured it out.  They are unions.  The struct chosen depending on your cpu arch.

#include <WinAPI.au3>

Global Const $MOVEFILE_REPLACE_EXISTING      = 0x1
Global Const $MOVEFILE_COPY_ALLOWED          = 0x2
Global Const $MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
Global Const $MOVEFILE_WRITE_THROUGH         = 0x8
Global Const $MOVEFILE_CREATE_HARDLINK       = 0x10
Global Const $MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20

Global Const $PROGRESS_CONTINUE = 0
Global Const $PROGRESS_CANCEL   = 1
Global Const $PROGRESS_STOP     = 2
Global Const $PROGRESS_QUIET    = 3

Global Const $CALLBACK_CHUNK_FINISHED = 0x00000000
Global Const $CALLBACK_STREAM_SWITCH  = 0x00000001

MoveFileWithProgress("D:\Media\Images\New Folder 1\Bailey Mason 10.jpg", "D:\Media\Images\New folder\Bailey Mason 10.jpg", _progress_callback)

ConsoleWrite(_WinAPI_GetLastErrorMessage())

Func MoveFileWithProgress(Const $existing_file_name, Const $new_file_name, Const $progress_routine, Const $flags = $MOVEFILE_COPY_ALLOWED, Const $data = '')
  Local Const $progress_callback = DllCallbackRegister($progress_routine, "dword", "uint;uint;uint;uint;dword;dword;handle;handle;void;")
 
  Local Const $result = DllCall("Kernel32.dll", "bool", "MoveFileWithProgressW", _
                                                "wstr",  "\\?\" & $existing_file_name, _
                                                "wstr",  $new_file_name, _
                                                "ptr",   DllCallbackGetPtr($progress_callback), _
                                                "ptr",  $data, _
                                                "dword", $flags)
 
  Return (@error Or Not $result) ? SetError(1, 0, False) : True  
EndFunc

volatile Func _progress_callback(Const $total_file_size, _
                                 Const $total_bytes_transferred, _
                                 Const $stream_size, _
                                 Const $stream_bytes_transferred, _
                                 Const $stream_number, _
                                 Const $callback_reason, _
                                 Const $source_file, _
                                 Const $destination_file, _
                                 Const $data)
  ConsoleWrite("Total Bytes Transferred: " & $total_bytes_transferred & @CRLF)
 
  Return $PROGRESS_CONTINUE
EndFunc
Edited by jaberwacky
Link to comment
Share on other sites

Actually it's quite funny to see what AutoIt does internally with the names of functions, when you try this code.

$funcname = MsgBoxMsgBox(0,"",FuncName($funcname))
If you ever use FuncName function then you know nothing about AutoIt, functions, and very little about programming in general. That function is fruit of somebody's brain fart. How can, and why did something like that became part of the language is question that, I think nobody can give sensible answer to.

Thanks for the explanation of internal working. It really wasn't necessary because you see... I know a little about that myself.

edit: const for callback param ever worked for you jaberwacky?

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Just found out, that it also works with GuiCtrlSetOnEvent, no need of WM_NOTIFY anymore :)

#cs
    DllCallbackRegister and Volatile
    test.au3

    Created on: 05.02.2014
        Author: Max Reble
#ce


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

;Here you can change the Sleep
Global Const $iSleep = 10


;same structure as in C
Global $tagStructTest = "int Wert1;int Wert2"
;for the WM command
Global $STOP = False


Opt("GuiOnEventMode",1)
;Create gui
GUICreate("Test")
$hTest = GUICtrlCreateButton("stop",150,150,100,100,$BS_MULTILINE)
GUICtrlSetOnEvent(-1,"_stop")




GUISetState()


;Create Callback. Return Value of Test() is ptr and first param is also ptr
$hCallBack = DllCallbackRegister("Test","ptr","ptr")
;Get the pointer
$pCallBack = DllCallbackGetPtr($hCallBack)
;and call the dll
$aDll = DllCall("libtestLibCallback.dll","int:cdecl","OnAutoItFunc","ptr",$pCallBack,"int",$iSleep)
If @error Then Exit MsgBox(16,"","ERR "&@error)
MsgBox(0,"","Stopped")

DllCallbackFree($hCallBack)

Exit


;Volatile is important. If you wouldn't use it, AutoIt (the GUI) would completly freeze
Volatile Func Test($pStruct)
    ;Create a new structure based on $tagStructeTest and fill it with the data received from the C pointer
    Local $tTest = DllStructCreate($tagStructTest,$pStruct)
    ;Fill the gui with data
    GUICtrlSetData($hTest,"push to stop "& @CRLF&$tTest.Wert1&@cRLF&$tTest.Wert2)
    ;If Button is pressed set Wert1 to -1. In c it will calculate + 1 so Wert1 will be 0. The C while will stop
    If $STOP Then $tTest.Wert1 = -1
    ;Return the Pointer of our struct
    Return DllStructGetPtr($tTest)
EndFunc



Func _stop()
    $STOP = True
EndFunc

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Trancexx, all AutoIt functions and keywords are (AFAIK) case-insensitive. Therefore, msgbox(...) and MsgBox(...) both work exactly the same. As a matter of fact, if someone wanted to write their code AS THOUGH THEY ARE SHOUTING IT WOULD WORK JUST THE SAME. Actually it's quite funny to see what AutoIt does internally with the names of functions, when you try this code.

$funcname = MsgBox
MsgBox(0,"",FuncName($funcname))

Yes, but case can make a difference with the way you read variables.

$sHitMode = "bounce"
$shitmode = "oh god why"
Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

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

×
×
  • Create New...