Page 1 of 1

VarSetCapacity() and NumPut() to V2?

Posted: 30 Jan 2024, 04:49
by 355 113
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

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

Posted: 30 Jan 2024, 10:50
by geek

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)

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

Posted: 30 Jan 2024, 12:14
by 355 113
Thank you very much, both versions work!