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
HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Hi tinku99,

ahkLabel and ahkFunction work well, also script is launched on addFile.

That's fantastic, thank you :)

I noticed 1 small problem, when you try to execute a label or function of first script launched by DllCall("...\ahkdll",...), instead of displaying an error message program crashes :?
IsLabel and IsFunc work fine, they both return 0.
Can this be fixed?

Also I noticed that when a MsgBox is shown from previous script and you call addFile, nothing happens.
If you get ExitThread + TerminateThread + Relaunch to work, this should be implemented here, I think. (simmilar to a reload in AutoHotkey.exe)

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
Fixed bug: when you tried to execute a label or function that didn't exist, the script crashed.
Also, ahkFunction now allows 2 parameters. Still does not return the return value of the target function, because it is sort of an asynchronous call within autohotkey through a msgmonitor type function.

I noticed that when a MsgBox is shown from previous script and you call addFile, nothing happens.

Are you sure? After you click away the MsgBox, see which script is active... For me the new one is and the old one isn't.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks tinku99,

I see now script is loaded fine but addfile script will not run when I press OK on MsgBox.

E.g. when you load following script (do not press OK) and then addfile it again and press OK (first MsgBox), second script will not run, though it is loaded fine.

#Persistent
MsgBox % A_TickCount

Btw. do ahkFunction, ahkLabel and addFile return a pointer to the function, label, line?

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

I see now script is loaded fine but addfile script will not run when I press OK on MsgBox.
Btw. do ahkFunction, ahkLabel and addFile return a pointer to the function, label, line?

Will fix it in the next release.
ahkFunction and ahkLabel return 0 on success, -1 if no such function or label exists.
In the future ahkFunction will return the result of the function call.
You can use FindFunc() (exported in the dll) to get a pointer to the function.

addfile returns a pointer to the first line in the newly added script.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
modifying the msgsleep function broke something.
Reverting temporarily.

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
ok, fixed ahklabel and ahkfunction again in v0.993.
You still have manually cleanup any running threads / msgboxes before overwriting the current script.
Recycling hotkeys is not supported between late includes yet.
That is next main thing to do.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Cool :D

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Hi tinku99,

how about to change the window class of AutoHotkey.dll to AutoHotkeyDll and AutoHotkeyDllGUI?

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

Hi tinku99,
how about to change the window class of AutoHotkey.dll to AutoHotkeyDll and AutoHotkeyDllGUI?

sure, in the next release :)

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Great :D

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Hi tinku99,

As I understand A_AhkPath in AutoHotkey.dll is reporting correct AutoHotkey.exe path but how do I get the path of dll?

As I understand to use exported function by the dll itself, I would need that or is there another way to call AddFile from Dll itself?

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

how do I get the path of dll?
is there another way to call AddFile from Dll itself?

You should already know the path of the dll if you loaded it...
But I will add a built in variable for the path of the dll in the next version.
You may not need the full path to call functions in the dll from itself... try
DllCall("AutoHotkey.dll\addFile", "str", "lateadded.ahk", "uchar", 1,"uchar" , 0, "Cdecl UInt")
Alternatively you can just use the builtin function
import("lateadded.ahk", 1, 0)
same thing for adding files from AutoHotkey_N.exe...
DllCall("AutoHotkey.exe\addFile", "str", "lateadded.ahk", "uchar", 1,"uchar" , 0, "Cdecl UInt")


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks tinku99,

I cannot get it to work using DllCall("AutoHotkey.exe\addfile",...

Import works fine in exe and dll but it does not work with pipes :?

Any chance import could accept text instead of file as well?

tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
[quote name="HotKeyIt"]
I cannot get it to work using DllCall("AutoHotkey.exe\addfile",...

Import works fine in exe and dll but it does not work with pipes :?
[/quote]you have to use addFile, not addfile. Case is important...
for pipes: see this comment by Lexikos
; AutoHotkey reads the first 3 bytes to check for the UTF-8 BOM "". If it is
; NOT present, AutoHotkey then attempts to "rewind", thus breaking the pipe.
Script := chr(239) chr(187) chr(191) Script
If you did this and its still not working, i am not sure... will look into it.
[quote]Any chance import could accept text instead of file as well?[/quote]yes, will probably add this feature eventually.[/quote]

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks tinku99,

I didn't know it is case sensitive, works fine now.

Here is my pipe example, it stucks when calling addFile.
When i change dwOpenMode to 1 it processes addFile but stucks at ConnectNamedPipe:
PIPE_NAME_ := A_TickCount
PIPE_GA_ := DllCall("CreateNamedPipe","str","\\.\pipe\" PIPE_NAME_,"uint"
					,[color=Red]2[/color],"uint",0,"uint",255,"uint",0,"uint",0,"uint",0,"uint",0)
PIPE_    := DllCall("CreateNamedPipe","str","\\.\pipe\" PIPE_NAME_,"uint"
					,[color=Red]2[/color],"uint",0,"uint",255,"uint",0,"uint",0,"uint",0,"uint",0)
if (PIPE_=-1 or PIPE_GA_=-1) {
	MsgBox CreateNamedPipe failed
}
DllCall(A_AhkPath . "\addFile","str","\\.\pipe\" . PIPE_NAME_,"Uchar",1,"Uchar",1,"Cdecl UInt")
MsgBox file added
DllCall("ConnectNamedPipe","uint",PIPE_GA_,"uint",0)
MsgBox pipe connected
DllCall("CloseHandle","uint",PIPE_GA_)
DllCall("ConnectNamedPipe","uint",PIPE_,"uint",0)
Script := chr(239) . chr(187) . chr(191) . "#Persistent`nGo:`nMsgBox pipe`nReturn"
if !DllCall("WriteFile","uint",PIPE_,"str",script,"uint",StrLen(script)+1,"uint*",0,"uint",0)
	MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
DllCall("CloseHandle","uint",PIPE_)
MsgBox
DllCall(A_AhkPath . "\ahkLabel", "str", "go", "Cdecl UInt")

It works fine using AutoHotkey.exe
PIPE_NAME_ := A_TickCount
PIPE_GA_ := DllCall("CreateNamedPipe","str","\\.\pipe\" PIPE_NAME_,"uint"
               ,2,"uint",0,"uint",255,"uint",0,"uint",0,"uint",0,"uint",0)
PIPE_    := DllCall("CreateNamedPipe","str","\\.\pipe\" PIPE_NAME_,"uint"
               ,2,"uint",0,"uint",255,"uint",0,"uint",0,"uint",0,"uint",0)
if (PIPE_=-1 or PIPE_GA_=-1) {
   MsgBox CreateNamedPipe failed
}
Run % A_AhkPath . " \\.\pipe\" . PIPE_NAME_
MsgBox file added
DllCall("ConnectNamedPipe","uint",PIPE_GA_,"uint",0)
MsgBox pipe connected
DllCall("CloseHandle","uint",PIPE_GA_)
DllCall("ConnectNamedPipe","uint",PIPE_,"uint",0)
Script := chr(239) . chr(187) . chr(191) . "#Persistent`nGo:`nMsgBox Pipe`nReturn"
if !DllCall("WriteFile","uint",PIPE_,"str",script,"uint",StrLen(script)+1,"uint*",0,"uint",0)
   MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
DllCall("CloseHandle","uint",PIPE_)
MsgBox