1. RE: Damn Unions

> -----Original Message-----
> From: jordah ferguson [mailto:jorfergie03 at yahoo.com]

> Is there some one out there who can help me link this structure
> to euphoria. My lack of understanding of what a union is has led to 
> this.

A union (as you may know) means that you can have either type of data stored
there.  I think you could probably simply use the dwOemId member, since the
second half of the struct is reserved.  If this causes problems when you
have to store something, you'll have to first fetch the entire DWORD and
then add the high word to your wProcessorArchitecture member (although I
really doubt you'll have to do this).

Matt Lewis
 
> typedef struct _SYSTEM_INFO { // sinf 
> 
>     union { 
>         DWORD  dwOemId; 
>         struct { 
>             WORD wProcessorArchitecture; 
>             WORD wReserved; 
>         }; 
>     }; 
>     DWORD  dwPageSize; 
>     LPVOID lpMinimumApplicationAddress; 
>     LPVOID lpMaximumApplicationAddress; 
>     DWORD  dwActiveProcessorMask; 
>     DWORD  dwNumberOfProcessors; 
>     DWORD  dwProcessorType; 
>     DWORD  dwAllocationGranularity; 
>     WORD  wProcessorLevel; 
>     WORD  wProcessorRevision; 
> } SYSTEM_INFO; 
>

new topic     » topic index » view message » categorize

2. RE: Damn Unions

Hey Jordah =)

Dont sweat the details on this too hard.  You have been working
with unions all along (kinda), you just didnt know it.  Heres a
good example I hope will make since.

wParam and lParam are 32 bit (DWORD) variables in memory.  Most
of the time you will use them whole (same as dwOemId).  If however
you are processing a WM_MOUSE or similar message, it is no longer
a DWORD but two WORD's (x and y positions).  This is a union.
It can be accessed either by DWORD or 2 WORDS.  In this case just
declare that whole union as DWORD dwOemId.  If you need the other
two elements, peek4u it out into a Euphoria variable and use 
Win32Libs built in lo_word() / hi_word() to extract the parts you
need...

Don Phillips

jordah ferguson wrote:
> Hi All,
> 
> Is there some one out there who can help me link this structure
> to euphoria. My lack of understanding of what a union is has led to 
> this.
> 
> typedef struct _SYSTEM_INFO { // sinf 
> 
>     union { 
>         DWORD  dwOemId; 
>         struct { 
>             WORD wProcessorArchitecture; 
>             WORD wReserved; 
>         }; 
>     }; 
>     DWORD  dwPageSize; 
>     LPVOID lpMinimumApplicationAddress; 
>     LPVOID lpMaximumApplicationAddress; 
>     DWORD  dwActiveProcessorMask; 
>     DWORD  dwNumberOfProcessors; 
>     DWORD  dwProcessorType; 
>     DWORD  dwAllocationGranularity; 
>     WORD  wProcessorLevel; 
>     WORD  wProcessorRevision; 
> } SYSTEM_INFO; 
> 
> Jordah Ferguson.
> 
>

new topic     » goto parent     » topic index » view message » categorize

3. RE: Damn Unions

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C2350B.5E9EE820
 charset=iso-8859-1

A Structure is the way we let the compiler know how we want a piece of RAM
used. It describes the layout of the memory area in terms of how the
compiler is supposed to store and fetch bytes from there. A Union is a way
of letting the compiler know that the same RAM location can be used
(described) in different ways. Normally a given RAM location contains data
that is used in only one way. However, occasionally there are times when we
can use the same area in RAM different ways.

So,

     union { 
         DWORD  dwOemId; 
         struct { 
             WORD wProcessorArchitecture; 
             WORD wReserved; 
         }; 

is saying that this piece of RAM can be thought of as either a single DWORD
or a single struct that contains two WORD items. For the purpose of mapping
this into Euphoria, the key is to locate the item in the union that is the
longest. This is then used to calculate the offset of the item that comes
after the union.

  constant  -- typedef struct _SYSTEM_INFO { // sinf 
     -- start of union
     SI_dwOemID     = 0,    -- length 4
     SI_wProcessorArchitecture = 0,  -- length 2, offset same as OemId
     SI_wReserved   = 2, -- length 2
     -- end of union
     SI_dwPageSize = 4, -- length 4
     SI_lpMinimumApplicationAddress = 8, -- length 4 
     SI_lpMaximumApplicationAddress = 12, -- length 4 
     SI_dwActiveProcessorMask = 16, -- length 4 
     SI_dwNumberOfProcessors = 20, -- length 4; 
     SI_dwProcessorType = 24, -- length 4; 
     SI_dwAllocationGranularity = 28, -- length 4; 
     SI_wProcessorLevel = 32, -- length 2; 
     SI_wProcessorRevision = 34, -- length 2; 
     SIZEOF_SYSTEM_INFO = 36 

------------
hth,
Derek

==================================================================
De informatie opgenomen in dit bericht kan vertrouwelijk zijn en 
is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht 
onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en 
de afzender direct te informeren door het bericht te retourneren. 
==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.


==================================================================

------_=_NextPart_000_01C2350B.5E9EE820
Content-Type: application/ms-tnef

new topic     » goto parent     » topic index » view message » categorize

4. RE: Damn Unions

Wow,

Thank you Matt, Chris and Don Phillips.... i didn't realise it was thaT 
easy, its just that union was so new to me and the structure looked 
complicated. Don Phillips, you've made it too easy for me to understand. 
All the same thank you All

/me: I don't think i will ever meet a helpful community, like the one in 
EU

Jordah
Don Phillips wrote:
> Hey Jordah =)
> 
> Dont sweat the details on this too hard.  You have been working
> with unions all along (kinda), you just didnt know it.  Heres a
> good example I hope will make since.
> 
> wParam and lParam are 32 bit (DWORD) variables in memory.  Most
> of the time you will use them whole (same as dwOemId).  If however
> you are processing a WM_MOUSE or similar message, it is no longer
> a DWORD but two WORD's (x and y positions).  This is a union.
> It can be accessed either by DWORD or 2 WORDS.  In this case just
> declare that whole union as DWORD dwOemId.  If you need the other
> two elements, peek4u it out into a Euphoria variable and use 
> Win32Libs built in lo_word() / hi_word() to extract the parts you
> need...
> 
> Don Phillips
> 
> jordah ferguson wrote:
> > Hi All,
> > 
> > Is there some one out there who can help me link this structure
> > to euphoria. My lack of understanding of what a union is has led to 
> > this.
> > 
> > typedef struct _SYSTEM_INFO { // sinf 
> > 
> >     union { 
> >         DWORD  dwOemId; 
> >         struct { 
> >             WORD wProcessorArchitecture; 
> >             WORD wReserved; 
> >         }; 
> >     }; 
> >     DWORD  dwPageSize; 
> >     LPVOID lpMinimumApplicationAddress; 
> >     LPVOID lpMaximumApplicationAddress; 
> >     DWORD  dwActiveProcessorMask; 
> >     DWORD  dwNumberOfProcessors; 
> >     DWORD  dwProcessorType; 
> >     DWORD  dwAllocationGranularity; 
> >     WORD  wProcessorLevel; 
> >     WORD  wProcessorRevision; 
> > } SYSTEM_INFO; 
> > 
> > Jordah Ferguson.
> > 
> >

new topic     » goto parent     » topic index » view message » categorize

5. RE: Damn Unions

Hi Derek,

merci beaucoup!

I was hoping you would help me out though yours came through last. Thank 
you

jordah
Derek Parnell wrote:
> A Structure is the way we let the compiler know how we want a piece of 
> RAM
> used. It describes the layout of the memory area in terms of how the
> compiler is supposed to store and fetch bytes from there. A Union is a 
> way
> of letting the compiler know that the same RAM location can be used
> (described) in different ways. Normally a given RAM location contains 
> data
> that is used in only one way. However, occasionally there are times when 
> we
> can use the same area in RAM different ways.
> 
> So,
> 
>      union { 
>          DWORD  dwOemId; 
>          struct { 
>              WORD wProcessorArchitecture; 
>              WORD wReserved; 
>          }; 
> 
> is saying that this piece of RAM can be thought of as either a single 
> DWORD
> or a single struct that contains two WORD items. For the purpose of 
> mapping
> this into Euphoria, the key is to locate the item in the union that is 
> the
> longest. This is then used to calculate the offset of the item that 
> comes
> after the union.
> 
>   constant  -- typedef struct _SYSTEM_INFO { // sinf 
>      -- start of union
>      SI_dwOemID     = 0,    -- length 4
>      SI_wProcessorArchitecture = 0,  -- length 2, offset same as OemId
>      SI_wReserved   = 2, -- length 2
>      -- end of union
>      SI_dwPageSize = 4, -- length 4
>      SI_lpMinimumApplicationAddress = 8, -- length 4 
>      SI_lpMaximumApplicationAddress = 12, -- length 4 
>      SI_dwActiveProcessorMask = 16, -- length 4 
>      SI_dwNumberOfProcessors = 20, -- length 4; 
>      SI_dwProcessorType = 24, -- length 4; 
>      SI_dwAllocationGranularity = 28, -- length 4; 
>      SI_wProcessorLevel = 32, -- length 2; 
>      SI_wProcessorRevision = 34, -- length 2; 
>      SIZEOF_SYSTEM_INFO = 36 
> 
> ------------
> hth,
> Derek
> 
> ==================================================================
> 
> 
> ==================================================================
> 
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu