Sign in to follow this  
Followers 0
GtaSpider

DllCallbackRegister with non freezing GUI (Volatile) Example

13 posts in this topic




No, there isn't any thread except the AutoIt's main one, but still seems interesting.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Even that said, I don't see why there is an exception for this keyword as all keywords start with a capital letter.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Trancexx, all AutoIt functions and keywords are (AFAIK) case-insensitive

 

Regardless of AutoIt's case-inesitivity, documentation should give correct casing.

 

I guess she already knows that.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
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 Froum

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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
2 people like this

"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

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

  • Similar Content

    • MarkBe
      By MarkBe
      Hi
      I am trying to check a number of applications are up to date and install the update if required. This will run as a shutdown script, pushed out through Group Policy.
      I am querying various registry keys to determine if
      The software is actually installed The software is at the correct version Once the need for update is determined then it calls another function to run the update.
      If the software is up to date or not installed, it moves down to the next software section which changes the registry key variables and calls the registry query function again
      I have managed to get the function for (un)installs to work but I am having trouble with the registry query function
      #NoTrayIcon #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> ; Here we go! ;########################################################################################################## ;Declare variables Global $RegKey86, $RegKey64, $RegValueName, $RegValueData, $CheckVersion86, $CheckVersion64 ; 7Zip ;########################################################################################################## _7Zip_Function() Func _7Zip_Function() ; Registry location and values that are checked for current software version ; Ensure the x64 key is preceeded with 'HKLM64' $RegKey86="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" $RegKey64="HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" $RegValueName="DisplayVersion" $RegValueData="16.04" ; Excecution ; --------------------------------------------------------------------------------------------------------- If _CheckSW() = 1 Then _UninstallOldVer() _InstallSW() EndIf EndFunc ;==>_7Zip_Function ; Functions ;########################################################################################################## Func _CheckSW() $CheckVersion86=RegRead ($RegKey86, $RegValueName) $CheckVersion64=RegRead ($RegKey64, $RegValueName) If $CheckVersion86=$RegValueData Or $CheckVersion64=$RegValueData Then Return 0 ElseIf $CheckVersion86="" And $CheckVersion64="" Then Return 0 Else Return 1 EndIf EndFunc ;==>CheckSW  
    • WoodGrain
      By WoodGrain
      Hi guys,
      Could someone please tell me what I'm doing wrong with this code?
      I'm trying to take user input and then run a function with the same name, but it's not calling the function.
      So in the below after pressing Shift+F8 I would enter the text (without quotes) "testFunc".
      As you can see I've also tried this with IF statements, I'm new to using Switch/Case.
      HotKeySet("+{F8}", RunManually) Func RunManually() ;Use a case statement with 1 hot key and an InputBox to manually run functions $funcName = InputBox("Which Func to Run?", "Enter the name of the function to run") MsgBox(0, "Entered value", $funcName) ;If $funcName = testFunc Then testFunc() ;If $funcName = test2Func Then test2Func() Switch $funcName Case testFunc MsgBox(0, "Calling", "Calling Function") testFunc() MsgBox(0, "Called", "Function call finished") Case test2Func MsgBox(0, "Calling", "Calling Function") test2Func() MsgBox(0, "Called", "Function call finished") EndSwitch EndFunc While 1 ;testFunc() Sleep(1000) WEnd Func testFunc() MsgBox(0, "func running", "Seems to work!") EndFunc Func test2Func() MsgBox(0, "func 2 running", "2 Seems to work!") EndFunc Thanks!
    • TheOnlyOne
      By TheOnlyOne
      So currently I have some code waiting for a status to change(there is different indicators to check if this status has changed) 
      Func oneRow($count) $globaltimer = _Timer_SetTimer($gui, 60000*10, "reset") $errTimer = TimerInit() While (1)         If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1)         Sleep(500)         MouseClick("right")         Sleep(600)         If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1)         If TimerDiff($errTimer) > 5000 Then             If PixelGetColor(1100, 310) = 0x707070 Or PixelGetColor(901, 305) = 0xE0E0E0 Or PixelGetColor(1043, 383) = 0xC6C6C6 Then                 Sleep(100)                 Send("{esc}")                 Sleep(1000)             EndIf         EndIf     WEnd .... EndFunc   ;==>oneRow The two timers is for error checking. This works just fine the problem comes when I go into the while 1 loop, my hotkeys at the top of the program seems to stop working, for an example 
      HotKeySet("{f1}", "stop") Func stop() Exit EndFunc ;==>stop Does not work at all after the while loop. The globaltimer is never called even though i tried setting the delay all the way down to 3 seconds. So I thought that maybe one of the function I use is blocking so the timer would never be called/the hotkey wouldn't work? if i make an delay just before the while loop the hotkey works just fine. Oh and the errTimer is supossed to not reset after 5 seconds but should keep making the check it does if five seconds have passed
    • alongsnake
      By alongsnake
      The best example is MouseClick, where you have MouseClick($Button, [$x, $y, [..........]]) Where if X is set, Y must be set too.
      I do know how to make it so that X and Y are optional, but I am not sure how to get Y mandatory if X is set. I did check the help, but didn't see anything there.
      Thanks in advance
    • TheDcoder
      By TheDcoder
      <snip>
      Hello , This time my script is throwing an error which does not make sense... How can I fix this?
      Code Snippet from the screenshot:
       
       
       P.S You saw it right, I am making a small handy tool for AutoIt Coders, TD