(ultimately, this callback would be called from a non-ahk program, so I can't just #include it as I would in scripts)
When executing the simpified scripts below, I get Error: An exception was thrown. Specifically: 0xc0000005
Code: Select all
#Requires AutoHotKey 2.1-alpha
^1::share_cb() ; send callback address to another script
send_cb_to_ahk(addr) {
MsgNum := DllCall("RegisterWindowMessage", "Str","test123")
PostMessage(MsgNum, addr,0,, HWND_BROADCAST:=0xFFFF)
}
cbAhkTest() {
return true
}
global addr_cbAhk := CallbackCreate(cbAhkTest) ;
share_cb() {
OutputDebug("sent addr_cbAhk=" addr_cbAhk)
send_cb_to_ahk(addr_cbAhk)
}
Code: Select all
#Requires AutoHotKey 2.1-alpha
^2::call_ahk() ; call the address we received previously from another script
global addr_cb_ahk := 0
MsgNum := DllCall("RegisterWindowMessage", "Str","test123")
OnMessage(MsgNum, SetGlobalCallbackAddr)
Persistent()
SetGlobalCallbackAddr(wParam, lParam, msg, hwnd) {
global addr_cb_ahk
addr_cb_ahk := wParam
OutputDebug("received addr_cb_ahk=" addr_cb_ahk)
}
call_ahk(){
if addr_cb_ahk = 0 {
OutputDebug("✗✗✗ callback isn't ready yet!")
} else {
OutputDebug("calling callback in another script @" addr_cb_ahk)
DllCall(addr_cb_ahk,"ptr")
}
}