Looks great. Thanks.Updated test version (including exe, dlls and bin)
AutoHotkey.dll
Started by
tinku99
, Apr 09 2009 07:28 PM
1328 replies to this topic
#136
-
Posted 24 February 2010 - 08:44 AM
For the test version I have changed DynaCall to support only one parameter definition since it reduces code a lot and should be the only way to go.
Small fix for pointer definition pP*, so now UIP, uip and ui* can be specified in parameter definition.
So now maximally 2 parameters can be passed: DynaCall("path and function of dll or function pointer", "parameter definition")
See this post for more information.
Also DynaCall uses only objects now instead #include <map> to save DYNATOKEN (reduces size of exe, dll, bin).
EDIT:
Updated AhkDllThread() function to use with compiled and not compiled scripts.
When using in compiled script, do not forget to Fileinstall,...dll,...dll.
For example:
Small fix for pointer definition pP*, so now UIP, uip and ui* can be specified in parameter definition.
So now maximally 2 parameters can be passed: DynaCall("path and function of dll or function pointer", "parameter definition")
See this post for more information.
Also DynaCall uses only objects now instead #include <map> to save DYNATOKEN (reduces size of exe, dll, bin).
EDIT:
Updated AhkDllThread() function to use with compiled and not compiled scripts.
When using in compiled script, do not forget to Fileinstall,...dll,...dll.
For example:
If 0 FileInstall,AutoHotkeyMini.dll,AutoHotkeyMini.dll ahk:=AhkDllThread("AutoHotkeyMini.dll") ahk.ahktextdll("MsgBox Thread") MsgBox % ahk.ahkgetvar.A_Now
AhkDllThread(dll=""){ static local v,v1,v2 static ResourceLoadLibrary:="ResourceLoadLibrary" static functions=" (LTrim Join `n ahkdll:ui=sss|ahktextdll:ui=sss|ahkReady:ui=|ahkReload:ui=|ahkTerminate:i=i| addScript:ui=sucuc|ahkassign:i=ss|ahkExecuteLine:ui=uiuiui|addFile:ui=sucuc| ahkFindFunc:ui=s|ahkFindLabel:ui=s|ahkgetvar:s=sui|ahkLabel:ui=s|ahkPause:i=s" ) If !(dll){ Loop % i { idx:=A_Index Loop,Parse,functions,| DynaCall(dll%idx% . "\" . A_LoopField) MemoryFreeLibrary(dllmodule%A_Index%) obj%A_Index%:="",dll%A_Index%:="",dllmodule%A_Index%:="" } i=0 return } else if (!FileExist(dll) && !A_IsCompiled){ MsgBox File: %dll%`ndoes not exist`, provide correct path for AutoHotkey.dll ExitApp } i++ dllmodule%i%:=A_IsCompiled ? %ResourceLoadLibrary%(dll) : MemoryLoadLibrary(dll) object := Object() Loop,Parse,functions,| { StringSplit,v,A_LoopField,: object[v1]:=DynaCall(MemoryGetProcAddress(dllmodule%i%,v1),v2) } obj%i%:=object dll%i%:=dll return obj%i% }
#138
-
Posted 24 February 2010 - 08:33 PM
I have wrapped exported functions of AutoHotkey_H.exe.
This script will work for compiled and not compiled scripts.
AhkExported(){ static init static functions:="ahkassign:i=ss|ahkExecuteLine:ui=uiuiui|ahkFindFunc:ui=s|ahkFindLabel:ui=s|ahkgetvar:s=sui|ahkLabel:ui=s|ahkPause:i=s" If (!init && init := Object()) { If !A_IsCompiled functions .= "|addFile:ui=sucuc|addScript:ui=sucuc" VarSetCapacity(file,512) DllCall("GetModuleFileName","UInt",DllCall("GetModuleHandle","UInt",0),"Uint",&file,"UInt",512) DllCall("LoadLibrary","Str",(A_IsCompiled ? A_ScriptFullPath : A_AhkPath)) Loop,Parse,functions,| { StringSplit,v,A_LoopField,: init[v1]:=DynaCall((A_IsCompiled ? A_ScriptFullPath : A_AhkPath) . "\" . v1,v2) } } return init }So a dll can now access main script as easy as main script the dll
This script will work for compiled and not compiled scripts.
If 0 FileInstall,AutoHotkey.dll,AutoHotkey.dll SetWorkingDir % A_ScriptDir exe:=AhkExported() dll:=AhkDllThread("AutoHotkey.dll") dll.ahktextdll[ "exe:=Object(" . &exe . ")`n" . "MsgBox AutoHotkey.dll jump to label in AutoHotkey.exe`n" . "exe.ahkLabel[""label""]" ] MsgBox GoSub Gosub, label ExitApp label: MsgBox Hello World! Return
#139
-
Posted 26 February 2010 - 09:42 PM
AutoHotkey_H Documentation
DynaCall Objects
Following calls will all do the same, just use the one which is appropriate:
AutoHotkey Download ( incl. AhkDll.chm + AhkExported() + AhkDll(Object/Thread) )
I have also build in functions Lock() and Unlock() to work with critical section because they are faster than user defined functions.
DynaCall Objects
Following calls will all do the same, just use the one which is appropriate:
dll.ahkassign.var := value dll.ahkassign[color=red].[/color]("var",value) dll.ahkassign("var",value) dll.ahkassign[color=red].var[/color](value) dll.ahkassign[color=red][[/color]"var",value[color=red]][/color] ;this will work as well MsgBox % ahk.ahkgetvar.var ;it is the same as MsgBox % ahk.ahkgetvar["var"] ;...
AutoHotkey Download ( incl. AhkDll.chm + AhkExported() + AhkDll(Object/Thread) )
I have also build in functions Lock() and Unlock() to work with critical section because they are faster than user defined functions.
If 0 ;AutoHotkeyMini.dll will be included in Compiled exe but never extracted, istead it is loaded via AhkDllThread() FileInstall,AutoHotkeyMini.dll,AutoHotkeyMini.dll SetWorkingDir % A_ScriptDir ;not required for compiled script #:=CriticalSection() ;see http://www.autohotkey.com/forum/viewtopic.php?t=51335 exe:=AhkExported() ;exported AutoHotkey.exe functions to DynaCall objects SplashTextOn,200,0,Loading Threads... Please wait... Loop 10 { dll:=AhkDllThread("AutoHotkeyMini.dll") ;exported AutoHotkeyMini.dll functions to DynaCall objects dll.ahktextdll[ "exe:=Object(" . &exe . ")`nCoordMode,ToolTip,Screen`nSleep,100`nSetBatchLines,-1`n" . "Loop`n" ;dynamic script . "ToolTip % Lock(" . # . ") . exe.ahkFunction[""func"",A_Index . """"] . UnLock(" . # . "),0," ((A_Index-1) * 20) ] dll.ahkPause(1),dll%A_Index%:=dll ;pause thread } Loop 10 ;unpause threads dll:=dll%A_Index%,dll.ahkPause(0) ;that way all threads will start at once SplashTextOff MsgBox Press OK to exit ExitApp func(p1){ ;this function is launched by each thread separately Return p1 }
#140
-
Posted 28 February 2010 - 12:09 AM
Hi Hotkeyit,
I am having trouble using the \ahkdll function from the latest build (HotKeyIt's version) referenced here : https://ahknet.autoh...yIt/AutoHotkey/
I am trying to run the example script from the documentaion here: <!-- m -->https://ahknet.autoh... ... ahkdll.htm<!-- m -->
If I use tinku99 version of autohotkey.dll the test script runs fine. But when I use the L48H6 build, the script running from the DLL errors out. The error box says something to the effect of:
A am also runing the script withe the version of autohotkey.exe that you provide with the downloand (Not Chris's version).
I can get the script to run if I use the \ahktextdll function (and insert the script inline, so to speak).
Any help would be appreciated.
Thanks, -Basi
BTW: Thank you and tinku99 for making this great DLL.[/url]
I am having trouble using the \ahkdll function from the latest build (HotKeyIt's version) referenced here : https://ahknet.autoh...yIt/AutoHotkey/
I am trying to run the example script from the documentaion here: <!-- m -->https://ahknet.autoh... ... ahkdll.htm<!-- m -->
Host Script ahkdll := DllCall("LoadLibrary", "str", A_ScriptDir . "\AutoHotkey.dll") sleep, 500 threadH := DllCall(A_ScriptDir . "\AutoHotkey.dll\ahkdll", "str", "dllclient.ahk", "str" , "", "str", "parameter1 parameter2", "Cdecl Int") Client Script ; dllclient.ahk #Persistent msgbox % "script parameters =" . A_ScriptParams . "script options = " . A_ScriptOptions return
If I use tinku99 version of autohotkey.dll the test script runs fine. But when I use the L48H6 build, the script running from the DLL errors out. The error box says something to the effect of:
Error at line 1. Line Text: MZ%$^#& <-- random text/characters here Error: This line does not contain a recognized action. The program will exit.
A am also runing the script withe the version of autohotkey.exe that you provide with the downloand (Not Chris's version).
I can get the script to run if I use the \ahktextdll function (and insert the script inline, so to speak).
Any help would be appreciated.
Thanks, -Basi
BTW: Thank you and tinku99 for making this great DLL.[/url]
#141
-
Posted 12 March 2010 - 04:27 PM
#142
-
Posted 12 March 2010 - 05:44 PM
HotKeyIt, can you please give me a little example of how to call AutoHotkey.dll from C.
#143
-
Posted 12 March 2010 - 06:28 PM
See example from tinku99
#144
-
Posted 12 March 2010 - 09:42 PM
Hotkey, I tried this
The script file "D:\??????????????????k" does not exist. Create it now?
#include <windows.h> #include <stdio.h> typedef int (*ahkdll)(char *, char *, char *) ; int main() { ahkdll ahkdll_; // Load DLL file HINSTANCE hinstLib = LoadLibrary("AutoHotkey.dll"); if (hinstLib == NULL) { printf("ERROR: unable to load DLL\n"); return 1; } // Get function pointer ahkdll_ = (ahkdll)GetProcAddress(hinstLib, "ahkdll"); if (ahkdll == NULL) { printf("ERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } // Call function. ahkdll_("D:\\MyScript.ahk", "", ""); // Unload DLL file FreeLibrary(hinstLib); return 0; }But I keep getting this error :
The script file "D:\??????????????????k" does not exist. Create it now?
#145
-
Posted 14 March 2010 - 07:15 AM
As it is Unicode you will need to pass wchar_t * :!:
#include <windows.h> #include <stdio.h> typedef int (*ahkdll)(wchar_t *, wchar_t *, wchar_t *) ; typedef int (*ahkReady)(); int main() { // Load DLL file HINSTANCE hinstLib = LoadLibrary("AutoHotkey.dll"); if (hinstLib == NULL) { printf("ERROR: unable to load DLL\n"); return 1; } // Get function pointer ahkdll ahkdll_ = (ahkdll)GetProcAddress(hinstLib, "ahkdll"); ahkReady ahkReady_ = (ahkReady)GetProcAddress(hinstLib, "ahkReady"); if (ahkdll_ == NULL || ahkReady_ == NULL) { printf("ERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } // Call function. ahkdll_(L"D:\\MyScript.ahk", L"", L""); // Wait for script to finish while (ahkReady_()) Sleep(50); // Unload DLL file FreeLibrary(hinstLib); return 0; }
#146
-
Posted 14 March 2010 - 10:36 AM
#147
-
Posted 14 March 2010 - 11:24 AM
It took me a while to figure out that HotkeyIt's versions was Unicode (as compared to Tinku99's version which is Ansi) . So I am posting the C# DLL Import prototype that worked for me, here.
C# prototype for the autohotkey.dll\ahkdll library call:
Here is an Example of the C# prototype for the ahkFunction call:
Also don't forget to put the autohotkey.dll and your script (myscript.ahk) in the \bin\debug folder when you are testing/running from the C# IDE.
Thanks again HotkeyIT and Tinku99 for this DLL.
-Basi
BTW: Maybe the Docs should mention that tinku99 version is ANSI (and is easier to call/use with Chris's version of autohotkey.exe) and that HotkeyIts version is Unicode which is easier to use with Lexicos autohotkey.exe version....
C# prototype for the autohotkey.dll\ahkdll library call:
[DllImport("AutoHotkey.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "ahkdll")] static extern int ahkdll([MarshalAs(UnmanagedType.LPWStr)] string scriptName, [MarshalAs(UnmanagedType.LPWStr)]string options, [MarshalAs(UnmanagedType.LPWStr)]string parameters);
Here is an Example of the C# prototype for the ahkFunction call:
[DllImport("AutoHotkey.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "ahkFunction")] static extern string ahkFunction([MarshalAs(UnmanagedType.LPWStr)]string functionName, [MarshalAs(UnmanagedType.LPWStr)]string p1, [MarshalAs(UnmanagedType.LPWStr)]string p2, [MarshalAs(UnmanagedType.LPWStr)]string p3, [MarshalAs(UnmanagedType.LPWStr)]string p4, [MarshalAs(UnmanagedType.LPWStr)]string p5, [MarshalAs(UnmanagedType.LPWStr)]string p6, [MarshalAs(UnmanagedType.LPWStr)]string p7, [MarshalAs(UnmanagedType.LPWStr)]string p8, [MarshalAs(UnmanagedType.LPWStr)]string p9, [MarshalAs(UnmanagedType.LPWStr)]string p10);
Also don't forget to put the autohotkey.dll and your script (myscript.ahk) in the \bin\debug folder when you are testing/running from the C# IDE.
Thanks again HotkeyIT and Tinku99 for this DLL.
-Basi
BTW: Maybe the Docs should mention that tinku99 version is ANSI (and is easier to call/use with Chris's version of autohotkey.exe) and that HotkeyIts version is Unicode which is easier to use with Lexicos autohotkey.exe version....
#148
-
Posted 14 March 2010 - 08:25 PM
#149
-
Posted 28 March 2010 - 07:23 PM
Hello buddy ,first thanks for all your cool libraries hehehe I really enjoy to use it.
Now my question... well I´m trying to implement threads handlig using your autohotkey_test version and the ahkdllThread, now I can only implement dynamic threads using the tinku99 approach (mandelbrot) with this one you have to use the Filecopy function and other stuffs... Can you give a translation of the maldelbrot example using your auothotkey_test (dynacall and AhkDllThread)
I think is something like this one:
But I really do not know where to put the thread functionality (for example to draw the figure) can you give me a hand?
Thank you very much
Now my question... well I´m trying to implement threads handlig using your autohotkey_test version and the ahkdllThread, now I can only implement dynamic threads using the tinku99 approach (mandelbrot) with this one you have to use the Filecopy function and other stuffs... Can you give a translation of the maldelbrot example using your auothotkey_test (dynacall and AhkDllThread)
I think is something like this one:
obj:=AhkDllThread(A_ScriptDir . "\AutoHotkeyMini.dll") DynaCall(obj.ahktextdll,"Persistent`nMsgBox")
But I really do not know where to put the thread functionality (for example to draw the figure) can you give me a hand?
Thank you very much
#150
-
Posted 12 April 2010 - 08:05 AM