A_AhkExe() error

Ask for help, how to use AHK_H, etc.
Okram
Posts: 24
Joined: 02 Oct 2013, 16:53

A_AhkExe() error

15 Apr 2019, 05:59

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
}
User avatar
tank
Posts: 2774
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: A_AhkExe() error

15 Apr 2019, 08:54

what does ahkthread look like?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
swagfag
Posts: 3068
Joined: 11 Jan 2017, 17:59

Re: A_AhkExe() error

15 Apr 2019, 10:15

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
}
Okram
Posts: 24
Joined: 02 Oct 2013, 16:53

Re: A_AhkExe() error

15 Apr 2019, 13:00

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?
swagfag
Posts: 3068
Joined: 11 Jan 2017, 17:59

Re: A_AhkExe() error

15 Apr 2019, 13:05

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
Last edited by swagfag on 15 Apr 2019, 15:03, edited 1 time in total.
HotKeyIt
Posts: 1889
Joined: 29 Sep 2013, 18:35
Contact:

Re: A_AhkExe() error

15 Apr 2019, 14:50

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!
Okram
Posts: 24
Joined: 02 Oct 2013, 16:53

Re: A_AhkExe() error

17 Apr 2019, 03:27

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?
HotKeyIt
Posts: 1889
Joined: 29 Sep 2013, 18:35
Contact:

Re: A_AhkExe() error

17 Apr 2019, 14:55

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
}
Okram
Posts: 24
Joined: 02 Oct 2013, 16:53

Re: A_AhkExe() error

18 Apr 2019, 01:50

Thanks, this works. Even with passing only one parameter.

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 1 guest