Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue Jan 20, 2009 6:42 am
Am I missing something here? I get an invalid memory access on "EndProcedure". I'm using PB 4.30.
Code: Select all
OpenWindow(0,0,0,320,240,"")
Procedure PointInClientRect(hWnd, x, y)
Pt.POINT\x=100
Pt.POINT\y=100
ScreenToClient_(WindowID(0),@Pt.POINT)
GetClientRect_(WindowID(0),@Rc.RECT)
Lib=OpenLibrary(#PB_Any,"User32.dll")
Ptr=GetFunction(Lib,"PtInRect")
CloseLibrary(Lib)
If Ptr
CallFunctionFast(Ptr,@Rc,@Pt)
EndIf
EndProcedure
PointInClientRect(WindowID(0),100,100)
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue Jan 20, 2009 6:48 am
I think I found the problem. I need to pass a quad or two longs instead of an address:
Code: Select all
Procedure PointInClientRect(hWnd, x, y)
Pt.POINT\x=100
Pt.POINT\y=100
ScreenToClient_(WindowID(0),@Pt.POINT)
GetClientRect_(WindowID(0),@Rc.RECT)
Lib=OpenLibrary(#PB_Any,"User32.dll")
Ptr=GetFunction(Lib,"PtInRect")
CloseLibrary(Lib)
If Ptr
CallFunctionFast(Ptr,@Rc,PeekL(@Pt),PeekL(@Pt+SizeOf(LONG)))
EndIf
EndProcedure
freak
PureBasic Team
Posts: 5940 Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany
Post
by freak » Tue Jan 20, 2009 6:48 am
The second parameter to PtInRect is a POINT structure itself, not just a pointer to it. So the stack gets messed up.
You can solve this by passing the x/y as separate parameters to get the same stack layout as the POINT structure would have on the stack.
btw, this will not work on PB x64. For it to work there you have to put the whole POINT structure into a quad and pass that as a single parameter. It will work on both x86 and x64 if you use the quad way and a prototype instead of CallFunctionFast() (it does not support quads)
[edit] so close!
quidquid Latine dictum sit altum videtur
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue Jan 20, 2009 7:00 am
But it should still work in x64 with CallFunctionFast if I push the x and y variables as longs, correct?
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue Jan 20, 2009 10:42 am
Use :
Works with PB x86 and x64.
Why are you loading the function from the dll?
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue Jan 20, 2009 12:07 pm
Ahhhh; fair enough!
As Freak says though, using a prototype would allow you to pass the entire point structure as a quad ala pt\y<<32+pt\x etc.
I may look like a mule, but I'm not a complete ass.
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue Jan 20, 2009 3:00 pm
I still love CallFunctionFast for quick one-line calls.
ABBKlaus
Addict
Posts: 1143 Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany
Post
by ABBKlaus » Tue Jan 20, 2009 6:28 pm
I wonder why you never responded to that thread
Isn´t it fixed ?
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue Jan 20, 2009 8:45 pm
It might be. I needed an immediate solution so I just called the dll directly.
wilbert
PureBasic Expert
Posts: 3942 Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands
Post
by wilbert » Thu Mar 01, 2012 10:13 am
Have you considered creating your own point in structure procedure ?
It's something that should be easy to create.