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

what means it would be deleted later? It doesn't add to the script? So I can create some functions several times(cause it can not do normally).
btw: I can each call a function use "ahkfunction("funcName", params)" or just ahkexec("funcName(params)").

Yes it is added and then removed from the script.

Note ahkExec will not return a value where ahkFunction will.

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
It more clear now!
Thank you very much!

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
Just notice "~VKFF::Return" workaroud in not suitable for autohotkeymini.dll :wink:

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

Just notice "~VKFF::Return" workaroud in not suitable for autohotkeymini.dll :wink:

True, thanks :(
I will change it for both to:
OnMessage(0,"")


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

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010

Changed :)

I download the lastest ahkdll, but still notify me "unknown directive #persistent". :cry:

ahkdll := AhkDllThread()
; ahkdll.ahktextdll("#NoTrayIcon`n OnMessage(0,`"`")")   ; fail!
ahkdll.ahktextdll("msgbox working`n OnMessage(0,`"`")")   ; it is ok, don't know why, but fail in get ahkready in debug mode
; ahkdll.ahktextdll()                  ; default setting still use "#persistent"
Loop{
   ToolTip, % ready := ahkdll.ahkready()           ; always fail when in debug mode
   if not ready
      Sleep, 100
   else{
      ToolTip
      break
   }
}
ahkdll.addscript("msgbox Success load", 1)
return
~VKFF::return
The above code have test both in ahk_l and ahk_h.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Try again, also make sure to clear your cache.

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
ahkdll := AhkDllThread()
ahkdll.ahktextdll()                ; ok, now!
While !ahkDll.ahkReady() ;wait for the script to be ready
Sleep 10
While AhkDll.ahkReady() ;wait for the dll to finish running its script
Sleep, 100
ahkdll.ahkexec("msgbox Success load")                         ; even this one is not working!
; ahkdll.addscript("msgbox Success load", 1)               [color=red] ; should I do the check every time I addscript/addfile and run it[/color]
; While !ahkDll.ahkReady() ;wait for the script to be ready
; Sleep 10
; While AhkDll.ahkReady() ;wait for the dll to finish running its script
; Sleep, 100
return
~VKFF::return
I'm sure I got the lastest version. But seems it's behavior is inconsistent, so I just try to add some check to ensure it's working!

But I'm not a luck man! :(

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
While !ahkDll.ahkReady() ;wait for the script to be ready

Sleep 10

While AhkDll.ahkReady() ;Why should the script finish??? It is persistent and won't finish, you do not need that line



aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
After try servel times, I'm fail!! Then I just go back to the previous one, seems it's all OK now!
The basic code, I can't run in the lastest version! :?:
ahkdll := AhkDllThread()
ahkdll.ahktextdll()
Sleep, 200
ahkdll.ahkexec("msgbox never show!")
~VKFF::return



AhkDllThread_GetVersion(Query:="FileDescription"){
   static CS := A_IsUnicode ? "W" : "A"
   FSz:=DllCall("Version\GetFileVersionInfoSize" CS, "Str",A_AhkPath, "UInt",0 )
   VarSetCapacity( FVI, FSz, 0 ),VarSetCapacity( Trans,8*(A_IsUnicode?2:1) )
   DllCall("Version\GetFileVersionInfo" CS, "Str",A_AhkPath, "Int",0, "UInt",FSz, "UInt",&FVI )
   DllCall("Version\VerQueryValue" CS, "UInt",&FVI, "Str","\VarFileInfo\Translation", "UIntP",Translation, "UInt",0 )
   DllCall("msvcrt\s" (A_IsUnicode ? "w": "" ) "printf", "Str",Trans, "Str","`%08X", "UInt",NumGet(Translation+0) )
   subBlock := "\StringFileInfo\" SubStr(Trans,-4) SubStr(Trans,1,4) "\" Query
   DllCall("Version\VerQueryValue" CS, "UInt",&FVI, "Str",SubBlock, "UIntP",InfoPtr, "UInt",0 )
   Return StrGet( InfoPtr )
}

AhkDllThread(dll:="AutoHotkey.dll",obj:=0){
   static
   local v
   static handleOfAhkdll,DynaCall:="DynaCall", MemoryLoadLibrary:="MemoryLoadLibrary",MemoryFreeLibrary:="MemoryFreeLibrary"
         ,ResourceLoadLibrary:="ResourceLoadLibrary", MemoryGetProcAddress:="MemoryGetProcAddress"
   static Trans, AHK_H:=(AhkDllThread_GetVersion()=="AutoHotkey_H")
   static functions :="
(Join
ahkKey:s|ahkFunction:s=sssssssssss|ahkPostFunction:i=sssssssssss|
ahkdll:t=ss|ahktextdll:t=ss|ahkReady:|ahkReload:ui=|
ahkTerminate:i|addFile:t=sucuc|addScript:t=si|ahkExec:ui=s|
ahkassign:ui=ss|ahkExecuteLine:t=tuiui|
ahkFindLabel:t=s|ahkgetvar:s=sui|ahkLabel:t=sui|ahkPause:s
)"
  static AhkDllThreadfunc :="
(Join`r`n
#NoTrayIcon
Pause
Return
AhkDllThread(dll:="AutoHotkey.dll",obj:=0,map:=""){
   static
   local v
   static functions := "ahkKey:s|ahkFunction:s=sssssssssss|ahkPostFunction:i=sssssssssss|"
                     . "ahkdll:t=ss|ahktextdll:t=ss|ahkReady:|ahkReload:ui=|"
                     . "ahkTerminate:i|addFile:t=sucuc|addScript:t=si|ahkExec:ui=s|"
                     . "ahkassign:ui=ss|ahkExecuteLine:t=tuiui|"
                     . "ahkFindLabel:t=s|ahkgetvar:s=sui|ahkLabel:t=sui|ahkPause:s"
   If !dll {
	  Loop `% i
      {
         idx:=A_Index
         `%MemoryFreeLibrary`%(dllmodule`%A_Index`%)
         obj`%A_Index`%:="",dll`%A_Index`%:="",dllmodule`%A_Index`%:=""
      }
      i:=0
      return
   } else if (!FileExist(dll)){
      MsgBox File: `%dll`% does not exist`, provide correct path for AutoHotkey.dll
      ExitApp
   }
   i++
   dllmodule`%i`%:= MemoryLoadLibrary(dll)
   if IsObject(obj)
      object:=obj
   else
      object := Object()
   object[""]:=dllmodule`%i`%
   LoopParse,`%functions`%,|
   {
      StrSplit,v,`%A_LoopField`%,:
      object[map="" ? v.1 ]:=DynaCall(MemoryGetProcAddress(dllmodule`%i`%,v.1),v.2)
   }
  obj`%i`%:=object
   dll`%i`%:=dll
   return &obj`%i`%
}
)"
  If !(dll){
    If !AHK_H {
         DllCall(_dll "\ahkFunction","Str","AhkDllThread","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str")
		 DllCall(_dll "\ahkTerminate")
		 DllCall("FreeLibrary","PTR",handleOfAhkdll)
		 handleOfAhkdll:="",_dll:=""
		 Return
      }
      Loop % i
      {
         idx:=A_Index
         %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
   }
   If !AHK_H {
      If (init || init := DllCall("LoadLibrary","Str",_dll := dll)){
         If DllCall(dll "\ahktextdll","Str",AhkDllThreadfunc,"Str","","Str","","Cdecl UInt")
            Return Object(0+DllCall(dll "\ahkFunction","Str","AhkDllThread","Str",dll,"Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","Str","","CDecl Str"))
         else
            Return 0,ErrorLevel:="Could not load AutoHotkey.dll"
      } else {
         MsgBox Could not load %dll%
         Return 0
      }
   }
   i++
   dllmodule%i%:=A_IsCompiled ? %ResourceLoadLibrary%(dll) : %MemoryLoadLibrary%(dll)
   if IsObject(obj)
    object:=obj
   else
    object := Object()
  object[""]:=dllmodule%i%
   LoopParse,%functions%,|
   {
      StrSplit,v,%A_LoopField%,:
      object[map="" ? v.1 ]:=%DynaCall%(%MemoryGetProcAddress%(dllmodule%i%,v.1),v.2)
   }
  obj%i%:=object
   dll%i%:=dll
   return obj%i%
}
Sorry for boring you!

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

Sorry for boring you!

The sooner we find the bugs the better ;)
Thank You.

Try latest version.

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
lol :lol:
Thank you, and I notice the dll size is also decreased a little! :wink:

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010
Suggestion:
ahkdll := AhkDllThread()
ahkdll.ahktextdll()
msgbox % "ahkgetvar sth value is " ahkdll.ahkgetvar("nothing")
msgbox % "Suppose to empty, but ahkgetvar sth addr is " ahkdll.ahkgetvar("nothing", 1)
I think ahkgetvar(var, 1) should return nothing if var is not existence for meaningful!
And currently, ahkgetvar(var) only return string. But if the var is object return the "object" (or even the addr of object) instead of empty maybe very useful.

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

I think ahkgetvar(var, 1) should return nothing if var is not existence for meaningful!

ahkgetvar uses FindOrAddVar so the variable will be added anyway.

And currently, ahkgetvar(var) only return string. But if the var is object return the "object" (or even the addr of object) instead of empty maybe very useful.

You can already get the refference to the variable ahkgetvar(var, 1) and I do not see a way how to make it possible to return objects.
When using COM, you can get a safe array using ahkgetvar but not an ahk object.

aSEioT
  • Members
  • 87 posts
  • Last active:
  • Joined: 31 Oct 2010

You can already get the refference to the variable ahkgetvar(var, 1) and I do not see a way how to make it possible to return objects.

OK, maybe I'm not make it clear!
If the var we get is an object, we can return string "object" to indicate the var type and distinct it with blank var. Or we may have other function 'ahkgetvartype' or similar.