Page 1 of 1

A_AhkExe() error

Posted: 15 Apr 2019, 05:59
by Okram
Hi, I have an issue with a script using A_AhkExe function - Access Violation error pops up when I try to reload the script. The script runs ok until Alt+X hotkey is pressed. This happens in any script where A_AhkExe is present.

I tried to put the DllCall part to a new line and it works, however I still get an error from time to time, not sure this is the right solution. You provided me with the function long time ago and I wonder if there is an update? Thanks.

Code: Select all

string:="
(
#Persistent

!y::
Input(""This is my Text"")
return

!x::Reload

Input(Text){
  DllCall(A_AhkExe() ""\ahkFunction"",""Str"",""MyFunction"",""Str"", Text, ""Cdecl Str"")
  return
}

A_AhkExe(){
  static e,i:=VarSetCapacity(e,520) DllCall(""GetModuleFileName"",PTR,0,Str,e,UInt,260) VarSetCapacity(e,-1)
  return e
}
)"

dll0:=ahkthread(string)
return

MyFunction(Text){
  msgbox % Text
  return
}

Re: A_AhkExe() error

Posted: 15 Apr 2019, 08:54
by tank
what does ahkthread look like?

Re: A_AhkExe() error

Posted: 15 Apr 2019, 10:15
by swagfag
what is the purpose of this script? if its to call functions from the script that launched the thread u could try this instead:

Code: Select all

Thread := AhkThread("
(
	Main := AhkExported()
	Main.AhkFunction(""quit"")
)")

quit() {
	MsgBox quitting
}

Re: A_AhkExe() error

Posted: 15 Apr 2019, 13:00
by Okram
Thanks. The purpose of the script is to run a function in a main script from ahk thread.
Are there disadvantages of using AhkExported vs A_AhkExe() method?
Can AhkFunction use multiple arguments of different types?

Re: A_AhkExe() error

Posted: 15 Apr 2019, 13:05
by swagfag
Okram wrote:
15 Apr 2019, 13:00
Are there disadvantages of using AhkExported vs A_AhkExe() method?
idk we'll have to wait for @hotkeyit to weigh in on this.
Okram wrote:
15 Apr 2019, 13:00
Can AhkFunction use multiple arguments of different types?
idk try it. probably well apparently not

Re: A_AhkExe() error

Posted: 15 Apr 2019, 14:50
by HotKeyIt
You should use AhkExported for simplicity, otherwise you need to pass all 10 parameters: DllCall(A_AhkExe ""\ahkFunction"",""Str"",""MyFunction"",""Str"", Text, ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Str"", "", ""Cdecl Str"")
Can AhkFunction use multiple arguments of different types?
No, only string is supported here!

Re: A_AhkExe() error

Posted: 17 Apr 2019, 03:27
by Okram
Thanks, I'll use AhkExported, it seems equally fast and reliable.

Nevertheless, I tried your suggestion to pass all 10 parameters but the error still pops up. The problem must be with the AhkExe function - I found out that it worked after modifiying it from

Code: Select all

A_AhkExe(){
  static e,i:=VarSetCapacity(e,520) DllCall(""GetModuleFileName"",PTR,0,Str,e,UInt,260) VarSetCapacity(e,-1)
  return e
}
to

Code: Select all

A_AhkExe(){
  static e,i:=VarSetCapacity(e,520) 
  DllCall(""GetModuleFileName"",PTR,0,Str,e,UInt,260) VarSetCapacity(e,-1)
  return e
}
Is this is proper solution?

Re: A_AhkExe() error

Posted: 17 Apr 2019, 14:55
by HotKeyIt
Try this

Code: Select all

A_AhkExe(){
  static e,i:=VarSetCapacity(e,520),i1:=DllCall(""GetModuleFileName"",PTR,0,Str,e,UInt,260), i2:=VarSetCapacity(e,-1)
  return e
}

Re: A_AhkExe() error

Posted: 18 Apr 2019, 01:50
by Okram
Thanks, this works. Even with passing only one parameter.