1. c structs
I'm trying to convert some structures to eu, and I'm not sure of how
some things are stored.
for example, here are some VB type declares:
Type POINTAPI
x As Long
y As Long
End Type
Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
what would the struct size and offsets be? does a struct use any bytes
itself, for sizeOf maybe?
what about c_type arrays? and fixed length strings?
Chris
2. Re: c structs
Try this:
include tk_mem.e
-- Type POINT
ptX = allot( Long ),
ptY = allot( Long ),
SIZEOF_POINT = allotted_size(),
-- Type MSG
msgHWnd = allot( Long ),
msgMessage = allot( UInt ),
msgWParam = allot( Long ),
msgLParam = allot( Long ),
msgTime = allot( DWord ),
msgPtX = allot( Long ),
msgPtY = allot( Long ),
SIZEOF_MSG = allotted_size()
You can then do something like:
atom hPoint
hPoint = acquire_mem(0, SIZEOF_POINT)
store(hPoint, ptX, xvalue)
store(hPoint, ptY, yvalue)
and
xvalue = fetch(hPoint, ptX)
yvalue = fetch(hPoint, ptY)
Unless you want to use the low-level access methods:
-- Type POINT
contant
ptX = 0,
ptY = 4,
SIZEOF_POINT = 8,
-- Type MSG
msgHWnd = 0,
msgMessage = 4,
msgWParam = 8,
msgLParam = 12,
msgTime = 16,
msgPtX = 20,
msgPtY = 24,
SIZEOF_MSG = 28
You can then do something like:
atom hPoint
hPoint = allocate(SIZEOF_POINT)
poke4(hPoint + ptX, xvalue)
poke4(hPoint + ptY, yvalue)
and
xvalue = peek4s(hPoint+ptX)
yvalue = peek4s(hPoint+ptY)
-----------
Derek.
----- Original Message -----
From: "Chris Bensler" <bensler at mail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, March 29, 2002 11:28 PM
Subject: c structs
>
> I'm trying to convert some structures to eu, and I'm not sure of how
> some things are stored.
>
> for example, here are some VB type declares:
>
> Type POINTAPI
> x As Long
> y As Long
> End Type
>
> Type MSG
> hwnd As Long
> message As Long
> wParam As Long
> lParam As Long
> time As Long
> pt As POINTAPI
> End Type
>
> what would the struct size and offsets be? does a struct use any bytes
> itself, for sizeOf maybe?
>
> what about c_type arrays? and fixed length strings?
>
> Chris
>
>
>
>
3. Re: c structs
----- Original Message -----
From: "Chris Bensler" <bensler at mail.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: c structs
>
> Thanks Derek,
> Now I understand that much.
>
> What about arrays? and fixed length strings?
>
> EG.
> recName1(1) As Byte
> recName2 As String * 14
>
using tk_mem.e then
recName1 = allot(Byte)
recName2 = allot({14,Byte})
store(addr, recName1, value1)
store(addr, recName2, value2)
using low-level, then it depends on where in the structure these values are.
Using this method, you must count the offset from the start of the
structure. The field names represent an offset from the beginning of the
structure. To store and fetch data from the structure, you have to use
either poke() and peek().