Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AutoHotkey.dll


  • Please log in to reply
1328 replies to this topic
tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
** Revision 5 (04/22/2009)
dynamically load #include scripts
addFile(str file, uchar aAllowDuplicateInclude, uchar aIgnoreLoadFailure)
use this to load new functions or labels.
dynamic #Directives will probably not work.

Examples

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
added experimental threading support using multiple copies of the dll
see examples here
It turns out, I can just load the dll multiple times under different names.
giving thread local scripts. Shared thread variables should be easy with Lexikos' __alias(alias, alias_for) function in LowLevel..

Its probably best to keep separate copies of functions in scripts especially if you want to run time consuming functions at the same time: as in this example, however, sharing of functions is possible, if you avoid entangled variables (gui variables and builtin's such as A_Index and A_ScriptName), and don't run them at the same time.

V6. Merged with AutoHotkey v.1.0.48.02_L27

V1: AutoHotkey.dll compatible with v1.0.47.06, merged with ahkdll-0.6

_Slav2
  • Guests
  • Last active:
  • Joined: --
Could you please explain for noob. Autohotkey.dll is not like IrohAhk and still requires ahk-script in the text form? Could you please write example for something absolutely common like what to do if I want to execute two command script from C# using autohotkey.dll, is this possible?

Pixelgetcolor, color1, 100, 100
Sleep, 1000

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you are using C# or another .NET language, you are probably better off with IronAhk. This AutoHotkey.dll allows other programs to host AutoHotkey scripts, but does not (yet?) expose commands/functions directly to other languages.

_Slav2
  • Guests
  • Last active:
  • Joined: --
I am looking for a way how to faster convert existing autohotkey script to C# program, because it is not a problem to decompile any autohotkey script with proper decompiler. If I will have to parse 10000 line code to 10000 variables and send them as a parameters to autohotkey.dll then this is ok. Another question if we can use autohotkey.dll for this task, because of the license to be open source. :lol: If yes, then I need a little help on how to use this dll file. This is temporary solution of cause, finally we should work with IronAhk functions. Thabk you for your reply.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
You can host the dll in a csharp application using techniques described here and at codeproject. The second link includes a code example.

If you just modify the relevant lines with:
        	[DllImport("Invoke", CharSet=CharSet.Ansi)]
		public extern static int InvokeFunc(int funcptr, string script, string message, string title);
		static void Main(string[] args)	{
			int hmod=LoadLibrary("AutoHotkey.dll");
			int funcaddr=GetProcAddress(hmod, "ahkdll");
			int result=InvokeFunc(funcaddr, "dllclient.ahk", "", "");
...}
modified csharp example: here
You will also need the Invoke function code from the codeproject link.

I agree with Lexikos, that if you are using dotnet, you should probably invest more time in learning IronAhk.

I may expose more AutoHotkey built in functions, but there are a few other things that are higher on my todo list.

AutoHotkey.dll, is GPL v2.

Edit3:
Thanks to Lexikos for pointing out that the CharSet can be specified as ansi.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I am looking for a way how to faster convert existing autohotkey script to C# program, because it is not a problem to decompile any autohotkey script with proper decompiler.

Funny. C# decompilers aren't that much worse, or any more difficult.

Another question if we can use autohotkey.dll for this task, because of the license to be open source.

The GPL probably will not allow it.

You can host the dll in a csharp application using techniques described here and at codeproject. ... The only issue is that ahkdll() expects a char* for the parameters (scriptname),

It would be much more typical to use DllImport if the function doesn't need to be invoked dynamically. With DllImport you can specify that string parameters are marshalled in the Ansi character set.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007

Another question if we can use autohotkey.dll for this task, because of the license to be open source.

The GPL probably will not allow it.

With DllImport you can specify that string parameters are marshalled in the Ansi character set.


Linking against a GPL dll, including late binding, appears to bless the hosting application with GPL as well.

The codeproject example actually does use DllImport... It also allows dynamic function calls through the Invoke function written in asm which facilitates function pointers. Thanks for pointing out the solution to the unicode to ansi translation problem.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
callbacks into python are fairly straightforward with ctypes.
Python 3.x example:
python host
ahk client
startup the python interpreter, and run the following

from ctypes import *
ahk = cdll.AutoHotkey

CMPFUNC = CFUNCTYPE(c_int, c_int)
def py_cmp_func(a):
     print("py_cmp_func", a)
     return a

cmp_func = CMPFUNC(py_cmp_func)

fx = create_string_buffer(str(cast(cmp_func, c_void_p).value))
pyclient = create_string_buffer("pyclient.ahk")   # no unicode in ahk
ahk.ahkdll(pyclient, "", fx)  

I don't know why the calling python functions from c example is so convoluted in the python documentation, requiring compilation of python and using the python.h header. I can see it if you're embedding python, but for extending it:

It was much easier to adapt the ctypes example here

_Slav2
  • Guests
  • Last active:
  • Joined: --

Funny. C# decompilers aren't that much worse, or any more difficult.

I am going to use Intellilock. http://www.eziriz.com/intellilock.htm to protect C# compilation. What options exist for autohotkey code? I could find nothing but found decompiler which decompile everything instead :lol: Sorry for off-top, thank you for your replies.

harry.liang
  • Members
  • 3 posts
  • Last active: May 13 2009 02:14 PM
  • Joined: 10 May 2009

If you are using C# or another .NET language, you are probably better off with IronAhk. This AutoHotkey.dll allows other programs to host AutoHotkey scripts, but does not (yet?) expose commands/functions directly to other languages.


I love python and I love autohotkey, I am looking forward calling ahk commands/functions directly in python!

harry.liang
  • Members
  • 3 posts
  • Last active: May 13 2009 02:14 PM
  • Joined: 10 May 2009

If you are using C# or another .NET language, you are probably better off with IronAhk. This AutoHotkey.dll allows other programs to host AutoHotkey scripts, but does not (yet?) expose commands/functions directly to other languages.


I love python and I love autohotkey, I am looking forward calling ahk commands/functions directly in python!


Nobody care about this feature?

AHKnow
  • Members
  • 121 posts
  • Last active: May 17 2009 09:11 PM
  • Joined: 03 Jul 2004
OMG. Have not been around in a while, come back and this. Good damn job.

EverReef
  • Guests
  • Last active:
  • Joined: --

I love python and I love autohotkey, I am looking forward calling ahk commands/functions directly in python!


same here with php

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007

OMG. Have not been around in a while, come back and this. Good damn job.

Thanks AHKnow. :)

Here is a AutoHotkey.dll in Emacs:patch and binaries.
Get a regular distribution of emacs, and just replace the bin folder with the ahkEmacs binaries.
Features added to emacs:
Access to pointers. (strings for now, will add pointers to other LispObjects )
Callback to eval.
SendMessage.

Instructions for demo.
do meta-x ielm in emacs followed by...
(loadmodule "dllclient.ahk" "" "parameter")
(setq message "hello from emacs")
(sendmsg message)
(pointer message)
;; from ahk side, press F3, to eval an expression in emacs
;; press F1 from ahk side to use emacs pointer for access to emacs string