byte ptr to object

BlitzMax Forums/BlitzMax Programming/byte ptr to object

Chris C(Posted 2006) [#1]
I getting a byte ptr returned from a C library
this is one of many pointers set from max

here o is an instance of a type

dGeomSetData(o.geom,o)

when I get the data returned
Function CollisionCallback(data:Byte Ptr,g1:Int,g2:Int)

how can I turn data into a type?

Local o:odeent=odeent(data)
gives me...
Compile Error: Unable to convert from 'Byte Ptr' to '<unknown>'


ImaginaryHuman(Posted 2006) [#2]
Local o:BytePtr=odeent(data)

then do with it what you like, eg.

Local a:Int=Int(odeent(data))


Ziltch(Posted 2006) [#3]
If you are redefining 'o' from a type to a byte ptr , how do you then access the fields in the 'o' type ?


Fabian.(Posted 2006) [#4]
To convert an object o to a byte ptr p you can write:
Local p:Byte Ptr = Byte Ptr o
To convert a byte ptr p to an object o you can write:
Local o:Object ; ( Byte Ptr Ptr Varptr o ) [ 0 ] = p - 8
So instead of:
Local o:odeent=odeent(data)
You could write:
Local o:odeent; (Byte Ptr Ptr Varptr o)[0]=data-8