A note re.
VarSetCapacity(_hwnd, 4, 0), which is used in the script, and which is correct.
This *is* 64-bit compatible.
It does *not* need to be this:
VarSetCapacity(_hwnd, A_PtrSize, 0).
Note: when I tested on Windows 7, this hWnd had the class 'Progman'.
Firstly, the FindWindowSW method specifies a pointer to a long. A long is a 32-bit signed integer, i.e. *4* bytes.
IShellWindows::FindWindowSW (exdisp.h) | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/api/exdisp/nf-exdisp-ishellwindows-findwindowsw
Type: long*
A handle for the window matching the specified search criteria, or NULL if no such window was found.
Secondly, although window handles use the pointer type (8 or 4 bytes), window handles are guaranteed to have 32-bit values (4 bytes) in Windows, for both 64-bit and 32-bit versions.
winapi - What is the range of a Windows HANDLE on a 64 bits application? - Stack Overflow
https://stackoverflow.com/questions/18266626/what-is-the-range-of-a-windows-handle-on-a-64-bits-application
Interprocess Communication Between 32-bit and 64-bit Applications - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
64-bit versions of Windows use 32-bit handles for interoperability. When sharing a handle between 32-bit and 64-bit applications, only the lower 32 bits are significant, so it is safe to truncate the handle (when passing it from 64-bit to 32-bit) or sign-extend the handle (when passing it from 32-bit to 64-bit). Handles that can be shared include handles to user objects such as windows (HWND), handles to GDI objects such as pens and brushes (HBRUSH and HPEN), and handles to named objects such as mutexes, semaphores, and file handles.
Some code re. truncation and sign-extension:
Code: Select all
;q:: ;sign-extend/truncate
;sign-extend 32-bit number to 64-bit number (copy the leftmost bit leftwards)
;truncate 64-bit number to 32-bit number
vNum := 0x80000000
;vNum := (vNum << 32) >> 32 ;sign-extend
vNum := vNum << 32 >> 32 ;sign-extend ;equivalent to line above
MsgBox, % Format("0x{:X}", vNum) ;0xFFFFFFFF80000000
vNum &= 0xFFFFFFFF
MsgBox, % Format("0x{:X}", vNum) ;0x80000000
vNum := 0x7FFFFFFF
;vNum := (vNum << 32) >> 32 ;sign-extend
vNum := vNum << 32 >> 32 ;sign-extend ;equivalent to line above
MsgBox, % Format("0x{:X}", vNum) ;0x7FFFFFFF
vNum &= 0xFFFFFFFF
MsgBox, % Format("0x{:X}", vNum) ;0x7FFFFFFF
return