Problem with Extern
BlitzMax Forums/BlitzMax Programming/Problem with Extern
| ||
| Sorry to ask so many questions, but everyone is totally helpful which rocks! Hopefully I'll be able to give more back later, like I did with Blitz PLus. Anyway ... consider this test code:
Type TPoint
Field X
Field Y
End Type
Extern "win32"
Function GetCursorPos%(point:TPoint)
End Extern
Function ccGetCursorPos:TPoint()
'Returns a TPoint
Local point:TPoint = New TPoint
If Not GetCursorPos(point) Then
RuntimeError ("Error Getting Cursor Pos")
Return Null
Else
Return point
EndIf
End Function
Graphics 800,600,0
Repeat
Cls
Local point:Tpoint = ccGetCursorPos()
Flip
Until KeyHit(KEY_ESCAPE)
When I run it the BlitzMax output window fills up with error messages like this: bad refs:obj=$10bbb40 refs=$1d1 Now this function used to work in BlitzPlus, I used this in the user32.decls file: User32_GetCursorPos%(lpPoint*):"GetCursorPos" note that lpPoint is a pointer to TPoint. I tried using var in Max like this: Function GetCursorPos%(var point:TPoint) but it won't compile. Any ideas where I'm going wrong? I jsut want to pass a Tpoint to the windows function and have it filled out by the windows function, simple really. |
| ||
Type TPoint
Field X
Field Y
End Type
Extern "win32"
Function GetCursorPos%(point:Byte Ptr)'The API is expecting a byte ptr
End Extern
Function ccGetCursorPos:TPoint()
'Returns a TPoint
Local point:TPoint = New TPoint
If Not GetCursorPos(point) Then
RuntimeError ("Error Getting Cursor Pos")
Return Null
Else
Return point
EndIf
End Function
Graphics 800,600,0
Repeat
Cls
Local point:Tpoint = ccGetCursorPos()
DrawText point.X + " : " + point.Y, 12, 12
Flip
Until KeyHit(KEY_ESCAPE) |
| ||
| Spiffing! I knew it was something to do with Max Pointers, thanks :-) |