[func][v2] xDllCall - asynchronous DllCall

Post your working scripts, libraries and tools
Helgef
Posts: 3721
Joined: 17 Jul 2016, 01:02
Contact:

[func][v2] xDllCall - asynchronous DllCall

09 Jan 2019, 07:27

This is a function similar to DllCall, but the target function is called in a parallel (non-script) thread, and executes concurrently with the script thread (assuming CPU resources are sufficient).

Simple example,

Code: Select all

xDllCall(script_callback, "MessageBox", "ptr", 0, "str", msg, "str", title, "uint", options, "uint") ; shows a message box
; script continues to run while the function (MessageBox) executes.
; When the function, MessageBox, returns, the function script_callback is called with the result.
Please see the documentation, source and more examples available on :arrow: github. Please note that the links go to an example branch in an unfinished library. It is not recommended that anyone tries to use the library for anything else than the function in this example branch.

Cheers :rainbow: .
User avatar
kczx3
Posts: 823
Joined: 06 Oct 2015, 21:39

Re: [func][v2] xDllCall - asynchronous DllCall

09 Jan 2019, 20:22

This is fantastic. And the alpha lib is seriously impressive

On a barely related note, I was just looking at ReadFileEx for asynchronous file reading!
User avatar
cyruz
Posts: 268
Joined: 30 Sep 2013, 13:31

Re: [func][v2] xDllCall - asynchronous DllCall

09 Jan 2019, 21:18

Hi Helgef,

can this be considered a reliable method to do multithreading?

I was browsing your code repo and found also threadFunc. How does this compare to it?

I found also other interesting stuff in the xlib repo, but the thing is quite complex :D :D

Thank you!
ABCza on the old forum.
My GitHub.
Helgef
Posts: 3721
Joined: 17 Jul 2016, 01:02
Contact:

Re: [func][v2] xDllCall - asynchronous DllCall

11 Jan 2019, 09:10

Hello kczx3 and cyruz, thank you for taking an interest :wave: .
cyruz wrote:can this be considered a reliable method to do multithreading?
That is what it (the library) is designed to facilitate. In the case of this function (xDllCall), the library will create a new (real) thread, which entry point is outside of the interpreter, from which it will call the desired function passing the desired parameters, and retrieving the return value, and then sync with the script thread. After the script callback has returned, the library will clean up all allocated memory, close all handles and release all objects which aren't used. The library doesn't use any memory allocated by ahk, for any of its async. work. Hence it is reliable in the sense that there is never any conflict with the interpreter. That being said, the user must take responsibility on its end, that is, it has to make sure that whatever it calls and passes, doesn't cause any conflicts and is valid for the duration of the execution.
I was browsing your code repo and found also threadFunc. How does this compare to it?
threadFunc starts a new ahk pseudo-thread, just like, eg, settimer and triggering a hotkey does. It is unrelated to this topic, this topic is about executing non-script code, in real threads.
kczx3 wrote:On a barely related note, I was just looking at ReadFileEx for asynchronous file reading!
You can call that function with the built-in dllcall :). On a related note, you can call xDllCall from the completion routine (see ReadFileEx), if you want to process the read data asynchronously, for example, you can pass the buffer to strstr if you want to find a sub string in the file.

Cheers.
User avatar
nnnik
Posts: 4148
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [func][v2] xDllCall - asynchronous DllCall

11 Jan 2019, 12:05

It looks nice :) Well done - might use this in the future.
Recommends AHK Studio

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot], songdg and 38 guests