AutoHotkey Community

It is currently May 27th, 2012, 5:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 38  Next
Author Message
 Post subject:
PostPosted: February 24th, 2010, 9:44 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Updated test version (including exe, dlls and bin)

Looks great. Thanks.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 3:54 pm 
Offline
User avatar

Joined: April 4th, 2009, 8:19 pm
Posts: 1143
Location: Croatia
@HotKeyIt: Thanks! I understand it now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2010, 9:33 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
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:
Code:
If 0
   FileInstall,AutoHotkeyMini.dll,AutoHotkeyMini.dll
ahk:=AhkDllThread("AutoHotkeyMini.dll")
ahk.ahktextdll("MsgBox Thread")
MsgBox % ahk.ahkgetvar.A_Now

Code:
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%
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 26th, 2010, 10:42 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
I have wrapped exported functions of AutoHotkey_H.exe.
Code:
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 :D
This script will work for compiled and not compiled scripts.
Code:
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

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2010, 1:09 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
AutoHotkey_H Documentation

DynaCall Objects

Following calls will all do the same, just use the one which is appropriate:
Code:
dll.ahkassign.var := value
dll.ahkassign.("var",value)
dll.ahkassign("var",value)
dll.ahkassign.var(value)
dll.ahkassign["var",value]
;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.
Code:
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
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on March 12th, 2010, 6:43 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 5:27 pm 
Offline

Joined: May 28th, 2007, 4:09 pm
Posts: 8
Hi Hotkeyit,

I am having trouble using the \ahkdll function from the latest build (HotKeyIt's version) referenced here : http://www.autohotkey.net/~HotKeyIt/AutoHotkey/


I am trying to run the example script from the documentaion here: http://www.autohotkey.net/~tinku99/ahkd ... ahkdll.htm

Code:
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:

Code:
 
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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 6:44 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Merged with AHK_L latest build
AutoHotkey_L49H8

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on March 14th, 2010, 12:23 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 7:28 pm 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
HotKeyIt, can you please give me a little example of how to call AutoHotkey.dll from C. :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2010, 10:42 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
See example from tinku99

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 8:15 am 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
Hotkey, I tried this
Code:
#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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 11:36 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
As it is Unicode you will need to pass wchar_t * :!:
Code:
#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;
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on March 14th, 2010, 12:24 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 12:24 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Merged with AHK_L latest build
AutoHotkey_L49H8

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 9:25 pm 
Offline

Joined: May 28th, 2007, 4:09 pm
Posts: 8
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:
Code:
        [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:
Code:
        [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....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 28th, 2010, 8:23 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Merged with AHK_L latest build
+ Fix for DynaCall *pP parameter.
AutoHotkey_L50H9

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: a question my friend
PostPosted: April 12th, 2010, 9:05 am 
Offline

Joined: April 11th, 2010, 10:24 am
Posts: 23
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:

Code:
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 563 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 38  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group