Lexikos
Joined: 17 Oct 2006 Posts: 2364 Location: Australia, Qld
|
Posted: Sun Mar 23, 2008 10:41 am Post subject: Sub-classed window + WinGetClass = Access Violation |
|
|
AutoHotkey v1.0.47.06
WinGetClass causes an access violation if one of the script's windows is sub-classed by the script.
| Code: | Gui, +LastFound
Gui, Show, W100 H100
WindowProcOld := DllCall("SetWindowLong", "uint", WinExist(), "int", -4
, "int", RegisterCallback("WindowProc"))
WinGetClass, class, Window title required.
WindowProc(hwnd, uMsg, wParam, lParam) {
global WindowProcOld
Critical
; Contents not important.
return DllCall("CallWindowProc", "uint", WindowProcOld
, "uint", hwnd, "uint", uMsg, "uint", wParam, "uint", lParam)
} |
| Quote: | | Unhandled exception at 0x00551f56 in AutoHotkey.exe: 0xC0000005: Access violation reading location 0x0000000f. |
This occurs because WM_GETTEXT is sent to the GUI, triggering the window procedure. The script callback then executes and invalidates sArgVar[0], which WinGetClass attempts to dereference.
For details, see: Here comes the Drain Blamage again.... (Thanks to TodWulff for bringing this issue to my attention.)
Solution:
WinGetTitle resolves the OUTPUT_VAR (*sArgVar) macro once, before searching for the window. I suggest the same be done for WinGetClass. |
|