VarSetCapacity() and NumPut() to V2? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
355 113
Posts: 8
Joined: 15 Jun 2019, 04:12

VarSetCapacity() and NumPut() to V2?

30 Jan 2024, 04:49

What is the V2 analog of this V1 script line?

Code: Select all

VarSetCapacity(monitorInfo, 40), NumPut(40, monitorInfo)
Such a manual hint as: Use a buffer object for binary data/structures now! requires an old > new example
geek
Posts: 1053
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: VarSetCapacity() and NumPut() to V2?  Topic is solved

30 Jan 2024, 10:50

Code: Select all

monitorInfo := Buffer(40)
NumPut("UPtr", 40, monitorInfo)
Though technically speaking, the original code should have specified "Int" or "UInt" type instead of letting it default to "UPtr". The MONITORINFO struct's first field is DWORD type, which is equivalent to AHK's "UInt" type.

Code: Select all

monitorInfo := Buffer(40)
NumPut("UInt", 40, monitorInfo)
Also, you can (should?) use the buffer size to populate that field.

Code: Select all

monitorInfo := Buffer(40)
NumPut("UInt", monitorInfo.Size, monitorInfo)
355 113
Posts: 8
Joined: 15 Jun 2019, 04:12

Re: VarSetCapacity() and NumPut() to V2?

30 Jan 2024, 12:14

Thank you very much, both versions work!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, Draken and 24 guests