Is it possible - Execute DllCall from Array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Is it possible - Execute DllCall from Array

21 Apr 2017, 19:31

Hi all,

Say I have an array:

Code: Select all

arr:=["MessageBox", "Int", "0", "Str", "Press Yes or No", "Str", "Title of box", "Int", 4]
Is it possible to dynamically, for any array size, fill the arguments for DllCall such that this command is executed:

Code: Select all

WhichButton:=DllCall("MessageBox", "Int", "0", "Str", "Press Yes or No", "Str", "Title of box", "Int", 4)
Currently I can create a function but it wouldn't be dynamic:

Code: Select all

DynamicDll(args){
    if (args.length =3) {
        ret := DllCall(args[0],args[1],args[2])
    } else if (args.length = 5) {
        ret := DllCall(args[0],args[1],args[2],args[3],args[4])
    } ;... and so on
    return [ret,args]
}
Another potential option would be to generate the command as a string and then execute it with AHK_H...

And finally I assume it would be plausible to write (equivalent) code in C#/VB.Net and use CLR to execute said code.... It's pretty indirect but it has it's benefits - no need to install AHK_H.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Is it possible - Execute DllCall from Array  Topic is solved

21 Apr 2017, 19:54

Try variadic call:

Code: Select all

arr := ["MessageBox", "Int", "0", "Str", "Press Yes or No", "Str", "Title of box", "Int", 4]
MsgBox, % DllCall(arr*)
I hope that helps.
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Re: Is it possible - Execute DllCall from Array

21 Apr 2017, 20:17

I knew it had to be simple! Thanks wolf! :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 337 guests