Navigation:  Tutorial >

Managing bitfields with ot4xb

Previous pageReturn to chapter overviewNext page

See the following C structure definition from the Windows API

 

typedef struct { 

  unsigned short reserved:14, 

  fDeferUpd:1, 

  fAckReq:1; 

  short cfFormat; 

} DDEADVISE;

 

gwst does not manage bitfields automatically, so we need to find a workaround to define them manually.

 

BEGIN STRUCTURE DDEADVISE

   MEMBER WORD  _wFlags_

 

The first we need to make an suitable storage to our bitfields, in this case we defined the unsigned short _wFlags_ .

 

   DYNAMIC PROPERTY fDeferUpd IS MASK 0x4000 OF _wFlags_

   DYNAMIC PROPERTY fAckReq   IS MASK 0x8000 OF _wFlags_

 

This 2 bitfields in this case uses only 1 bit and are treated as logic so we only need to find an suitable mask and define the corresponding PROPERTY .. MASK

 

   MEMBER SHORT cfFormat

END STRUCTURE

 

In this example the reserved member is used just as a padding but if we want to use as a 14 bit unsigned value we need to build a workaround like this

 

   DYNAMIC PROPERTY reserved ;

           READ  nAnd( ::_wFlags_ , 0x3FFF) ;

           WRITE (::_wFlags_ := nOr(nAnd(v,0x3FFF),nAnd(0xC000,::_wFlags_))