Jump to content

Request for more info upon Volatile, Call, Callback

Recommended Posts


in this thread https://www.autoitscript.com/forum/topic/209820-unterminated-string-maybe-longer-than-5000-chars/ I noticed for the first time the function qualifier "Volatile", and don't really get the help file explanation:

The following rules apply to functions that are declared with this qualifier:

Callback function   During function execution the main AutoIt's message pump is not blocked as it normally is for non-Volatile callbacks.
COM event function  The execution is synchronous (see example).

What is the "autoit message pump"?

what is the callback function? Searching the help file I just find Call() ?

What are scenarios, where it's making sense to use the function qualifier "volatile"?


CU, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

I was also interested in it a bit when replying in that thread, I hadn't really ever seen Volatile before, meaning that I also haven't seen anyone else use it. I played around with the example a little bit, and it does change behavior in the example with it and without it. For instance, check out the page on the COM function that the example is putting Volatile in front of: https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768280(v=vs.85)

On the microsoft page it says: "Synchronous    No", and Volatile says: "COM event function    The execution is synchronous". If you run the example with and without Volatile, you get different results. With Volatile, it prevents the page from loading when you try to navigate to it (because BeforeNavigate2 sets Cancel to True). Without Volatile it doesn't prevent the page from loading, likely because the navigation request goes through before the $bIECancel actually takes effect. So Volatile making it synchronous allows the $bIECancel flag to actually cancel the request before it goes through.

I didn't understand and couldn't find a difference in behavior with a callback function, I'm also unsure of what the "AutoIt Message Pump" is. I just tried some basic tests with AdlibRegister and HotKeySet during a callback function and there was no noticeable difference.

For CallBack, I just used the example from: https://www.autoitscript.com/autoit3/docs/functions/DllCallbackRegister.htm

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

I use this keyword in some of my Excel, Word and Outlook example scripts.

Example: An event in Outlook is raised before a mail gets sent.
The user defined event function is called and if "volatile" is used Outlook waits for a reply of the function.
If you set the return value to True, the send operation is canceled.
If "Volatile" is not used Outlook calls the user defined event function but does not wait for a reply and immediately continues processing by sending the mail.

Edited by water
Typo fixed

My UDFs and Tutorials:


Active Directory (NEW 2022-02-19 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version - Download
Outlook Tools (2019-07-22 - Version - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

ADO - Wiki
WebDriver - Wiki


Link to comment
Share on other sites

I remember this old thread about non-blocking functions using volatile, a small example inside...


..also an incomplete attempt at MoveFileWithProgress by jaberwacky.

Some guy's script + some other guy's script = my script!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...