Jump to content

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

[AHK_H(+dll) / AHK_L / v2] AhkDllThread+AhkExported


  • Please log in to reply
274 replies to this topic
HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

It's great! And may thanks for implementing of CriticalObject :D

I wished this for AutoHotkey.dll for a long time and finally I got my head around that and I am really happy it works so flawless and fast so far :)

Flowerpiggy
  • Members
  • 45 posts
  • Last active: Dec 20 2012 02:57 PM
  • Joined: 22 Apr 2011
Dear HotKeyit and other geniuses,

autohotkey.dll and AhkDllThread works perfectly when the following script is uncompiled but after compiling it stops working and ErrorLevel becomes 1. Can you help?


;msgbox % remote_file_size . "," . silent_mode
remote_file_size := 2682462
SplashTextOn, , , Downloading,Preparing to download...
LinkDownloadFrom=https://ahknet.autohotkey.com/~Lexikos/AutoHotkey_L/AutoHotkey_L_Install.exe
FileSaveAs=%A_Temp%\gt4tsuite_up.exe
AHKDLL=%a_scriptdir%\AutoHotkey.dll

FileDelete,%FileSaveAs%

dll:=AhkDllThread(AHKDLL)
dll.ahktextdll("UrlDownloadToFile," . LinkDownloadFrom . "," . FileSaveAs)

While % !dll.ahkReady()
   Sleep, 10
size=0
SplashTextOff
Progress, m b1 w500 h100 , , Downloading GT4T Suite, Downloading...,Tahoma
While % dll.ahkReady()
{
   If FileExist(FileSaveAs)
      FileGetSize,size,%FileSaveAs%   
   tempvar := size . "/" . remote_file_size . " bytes Downloaded`nPress Escape to cancel download"   
   percent := size/remote_file_size * 100
   Progress, ,%tempvar% , Downloading GT4T Suite, Downloading...
   progress, %percent%
   ;TrayTip ,,%size% bytes Downloaded`nPress Escape to cancel download
   Sleep, 100
}
run, autohotkey.exe gt4t_up.ahk %silent_mode% 
ExitApp

Escape::
;ToolTip
dll.ahkterminate()
ExitApp


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Compiled AhkDllThread assumes that AutoHotkey.dll is included in compiled exe as a resource.
To be able to use AhkDllThread in compiled scripts, you will need following.
;Instead
AHKDLL=%a_scriptdir%\AutoHotkey.dll
;Use
If 0
  FileInstall,AutoHotkey.dll,AutoHotkey.dll

; Then to load dll use

dll:=AhkDllThread()
That's it :)

Guest_AutoHotkey_L
  • Guests
  • Last active:
  • Joined: --
This topics title seems to have changed from:

[AutoHotkey.dll] AhkDllThread+AhkDllObject+AhkExported

to:

[AutoHotkey.dll / AHK_L+_H] AhkDllThread+AhkExported


What is the fate of AhkDllObject? Should I be using something else instead?

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Yes, please use AhkDllThread, this is the only wrapper for AutoHotkey.dll now.

Guest_AutoHotkey_L
  • Guests
  • Last active:
  • Joined: --
Thanks for the response and clarification.

Apart from making sure AhkDllThread.ahk is available, does it seem like a simple search and replace will work? I haven't turned up any problems so far in my limited testing.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Yes that is correct, just replace the function and #includes.

Guest_AutoHotkey_L
  • Guests
  • Last active:
  • Joined: --
Thanks for the advice. So far things seem to be working out :)

BTW, would it be a problem to include SKAN's FileGetVersionInfo_AW in AHK_H's zip file (perhaps in Lib\FileGetVersionInfo.ahk)? It seems like that might make it easier for folks to get up and running.

FileGetVersionInfo_AW falls under SKAN's default license (public domain, IIUC), right?

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Will do, thanks.

Guest_AutoHotkey_L
  • Guests
  • Last active:
  • Joined: --
Thanks for the updated zip file with the included FileGetVersionInfo.ahk :)

On a separate note, I'm trying to use the Gui command via AhkDllThread and ahkFunction and have encountered a problem.

A simple GUI is created once, but a subsequent creation attempt (post Gui, Destroy) leads to a dialog box with the text "RegClass" and "Error: Could not create window" with ---> pointing at the line:

Gui, New
Below is some sample code to reproduce -- tested under Windows XP Pro SP3 with the Win32w AutoHotkey.dll, AutoHotkey.exe, and lib directory, freshly downloaded and extracted from your kindly provided AutoHotkey.zip.

I hope it's just a simple matter of local pilot error.

GuiProblemForAutoHotkeyDLL.ahk
SetWorkingDir, % A_ScriptDir

RunScript(ScriptPath, Input)
{
  AhkDll := AhkDllThread(A_ScriptDir . "\AutoHotkey.dll")
  ; XXX: probably a better way
  SFile := FileOpen(ScriptPath, "r")
  SText := SFile.Read()
  SFile.Close()
  AhkDll.ahkTextDll("#Persistent`n" . SText)
  OutputDebug, % "Value passing to script: " . Input
  Result := AhkDll.ahkFunction("EntryPoint", Input)
  OutputDebug, % "Script returned: " . Result
  AhkDll.Terminate()
  Return Result
}

gScriptPath := A_ScriptDir . "\test.ahk"
gInput := "please change me and close the window"

MsgBox, % "First result: " . RunScript(gScriptPath, gInput)
MsgBox, % "Second result: " . RunScript(gScriptPath, gInput)

Return

test.ahk
; gGuiAlive, GuiClose, and the While loop are hacks to 
; keep the function from returning until the gui goes away
EntryPoint(Input)
{
  global gGuiAlive
  ; see GUI, Storing and Responding to User Input for why 'static'
  static EditFieldValue := "" ; for: Gui, Add, Edit, ... vEditFieldValue
  gGuiAlive := True
  ;
  Gui, New
  Gui, Add, Edit, vEditFieldValue, % Input
  Gui, Show
  ; 
  While (gGuiAlive)
  {
    Sleep, 1000
  }
  ; save values in gui to variables
  Gui, Submit
  OutputDebug, % "EditFieldValue: " . EditFieldValue
  ; clean up the gui
  Gui, Destroy
  Return EditFieldValue
}

GuiClose:
{
  gGuiAlive := False
  Return
}


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks for reporting, that is fixed now, re-download the zip package.

Guest_AutoHotkey_L
  • Guests
  • Last active:
  • Joined: --
Thanks for the quick fix. Seems to work much better here now :)

  • Guests
  • Last active:
  • Joined: --
Hi HotkeyIt,

If I run the below code as compiled, it does not run the threads. If it's not compiled, it works. Am I missing something?

main thread
#Noenv
#Singleinstance, Force
#Persistent
SetWorkingDir %A_ScriptDir%

#include <AhkDllThread>	
oThreads := []   
strDllLocation := A_IsCompiled ? ".\AutoHotkey.dll" : ( A_PtrSize = 8 ) ? A_ScriptDir "\AutoHotkey64.dll" : A_ScriptDir "\AutoHotkey32.dll"
if !FileExist(strDllLocation) {
   msgbox The autohotkey.dll is not found.
   ExitApp
}
Loop, %A_ScriptDir%\threadscripts\*.ahk, 0, 1
{
	oThreads[A_Index] := AhkDllThread(strDllLocation)
	oThreads[A_Index].ahkdll(A_LoopFileFullPath)
}
msgbox done

Return

FileInstall, .\AutoHotkey.dll, -
hi.ahk in threadscript folder
#notrayicon
#persistent
msgbox hi
Return
F1::msgbox hi
hello.ahk in threadscript folder
#notrayicon
#persistent
msgbox hello
Return
F2::msgbox hello


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
AhkDllThread is designed to run AutoHotkey.dll from Memory/Resource.
So all you have to do is add following to your script:
If 0 {
   FileInstall,.\AutoHotkey.dll,- ; never executed 
   FileInstall,.\AutoHotkey64.dll,-
}


  • Guests
  • Last active:
  • Joined: --

AhkDllThread is designed to run AutoHotkey.dll from Memory/Resource.
So all you have to do is add following to your script:

If 0 {
   FileInstall,.\AutoHotkey.dll,- ; never executed 
   FileInstall,.\AutoHotkey64.dll,-
}

I just get the message, done, with the above code if it is compiled. And installed AutoHotkey.dll is a copy of AutoHotkey.dll in the x64w folder and I used Unicode 64-bit.bin for compiling so the file should be okey.

Could you test it in your environment?