Re: c structs

new topic     » goto parent     » topic index » view thread      » older message » newer message

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
> 
> 
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu