How to translate this to PB? Thought it would be easy... but the structure return makes me hit a wall.
ImportC ""
CGEventCreate(e)
CGEventGetLocation(e)
EndImport
e = CGEventCreate(0)
*p.CGPoint = CGEventGetLocation(e)
Debug *p\x
-> Illegal instruction (executing binary data?)
CGPoint point = CGEventGetLocation(event)
Re: CGPoint point = CGEventGetLocation(event)
With PB x64, when you call CGEventGetLocation, the CGPoint structure is returned in XMM0 and XMM1.
Explanation:
Possible ways on 64 bit macOS and Linux a structure is returned
* XMM0 - XMM1
* RAX - RDX
* RAX - XMM0
* ST0 - ST1
* Memory pointer provided by the caller (like a hidden first argument)
If a returned structure can be returned by registers (like CGPoint), it will.
If not, it is returned by memory the caller has to provide.
Another way to get the returned coordinates is by using my new VCall module
viewtopic.php?f=12&t=74092
Code: Select all
ImportC ""
CGEventCreate(e)
CGEventGetLocation(e)
EndImport
p.CGPoint
e = CGEventCreate(0)
CGEventGetLocation(e)
!movsd [v_p], xmm0
!movsd [v_p + 8], xmm1
Debug p\x
Debug p\y
Possible ways on 64 bit macOS and Linux a structure is returned
* XMM0 - XMM1
* RAX - RDX
* RAX - XMM0
* ST0 - ST1
* Memory pointer provided by the caller (like a hidden first argument)
If a returned structure can be returned by registers (like CGPoint), it will.
If not, it is returned by memory the caller has to provide.
Another way to get the returned coordinates is by using my new VCall module
viewtopic.php?f=12&t=74092
Code: Select all
UseModule VCall
VCReturn.VCReturn
*CGEventCreate = dlsym_(#RTLD_DEFAULT, "CGEventCreate")
*CGEventGetLocation = dlsym_(#RTLD_DEFAULT, "CGEventGetLocation")
Dim Args.VCArgument(1)
Args(0)\i = 0
e = VCall(*CGEventCreate, @Args(), @"i")
Args(0)\i = @VCReturn
Args(1)\i = e
VCall(*CGEventGetLocation, @Args(), @"ri")
p.CGPoint
p\x = VCReturn\xmm0
p\y = VCReturn\xmm1
Debug p\x
Debug p\y
Last edited by wilbert on Tue Nov 26, 2019 6:11 am, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: CGPoint point = CGEventGetLocation(event)
It works here with pb 5.7064 and Mac OS 10.12 I don't get any memory error.