Jump to content
  • Advertisement
Sign in to follow this  
Quak

WORD and DWORD

This topic is 5048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I had a look at win32 programming and now I am confused about the WORD and DWORD types. Which build-in typ(es) is/are behind them? And what exactly is a Low/High-Word, such as you can find in the wParam/lParam types? thx Quak

Share this post


Link to post
Share on other sites
Advertisement
WORD and DWORD are Win32-only. WORD is a 2-byte unsigned value (unsigned short) and DWORD is a 4-byte unsigned value (unsigned int).

There are two WORDs in a DWORD. The higher half is what HIWORD() returns and the lower half is what LOWORD() returns.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
WORD and DWORD are Win32-only. WORD is a 2-byte unsigned value (unsigned short) and DWORD is a 4-byte unsigned value (unsigned int).

There are two WORDs in a DWORD. The higher half is what HIWORD() returns and the lower half is what LOWORD() returns.

Keep in mind that you can still use a DWORD as a single value. The HIWORD/LOWORD functions just allow you to store and retrieve two WORD values.

Share this post


Link to post
Share on other sites
If you're using Visual Studio, just right click on WORD or DWORD and click "Go to Definition". It'll show you exactly what it is, and this is handy in the future when you encounter new types.

Share this post


Link to post
Share on other sites
Quote:
Original post by GroZZleR
If you're using Visual Studio, just right click on WORD or DWORD and click "Go to Definition".

Or even easier, just hover the mouse cursord over "WORD" for a second or two and it will pop up with its definition.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
WORD and DWORD are Win32-only. WORD is a 2-byte unsigned value (unsigned short) and DWORD is a 4-byte unsigned value (unsigned int).

There are two WORDs in a DWORD. The higher half is what HIWORD() returns and the lower half is what LOWORD() returns.


A DWORD is an unsigned long, not an unsigned int. A WORD is 16 bits and a DWORD is 32 bits. The D prefix in DWORD stands for double. On other words, DWORD mean double word, hence, 32 bits. If you read any old Assembly FAQ, you will find this information. You probebly know all thios already though.

Quak:
The WORD and DWORD are just type definitions of the build-in primitive data types. If you look in the WinDef.h file, you will find WORD & DWORDs type definitions; amung other type definitions.

Don't get confused with all those macros that M$ uses. The are just bit shift macros. The LOWORD and HIWORD retriev the low and hight order words of a DWORD. Hence, LOWORD and HIWORD return a WORD located in either the front or the back of a DWORD, so to speak. It's just a clever way of compressing information into one variable.

Share this post


Link to post
Share on other sites
Quote:
Original post by sakky
Quote:
Original post by JohnBolton
WORD and DWORD are Win32-only. WORD is a 2-byte unsigned value (unsigned short) and DWORD is a 4-byte unsigned value (unsigned int).

There are two WORDs in a DWORD. The higher half is what HIWORD() returns and the lower half is what LOWORD() returns.


A DWORD is an unsigned long, not an unsigned int. A WORD is 16 bits and a DWORD is 32 bits. The D prefix in DWORD stands for double. On other words, DWORD mean double word, hence, 32 bits. If you read any old Assembly FAQ, you will find this information. You probebly know all thios already though.

Quak:
The WORD and DWORD are just type definitions of the build-in primitive data types. If you look in the WinDef.h file, you will find WORD & DWORDs type definitions; amung other type definitions.

Don't get confused with all those macros that M$ uses. The are just bit shift macros. The LOWORD and HIWORD retriev the low and hight order words of a DWORD. Hence, LOWORD and HIWORD return a WORD located in either the front or the back of a DWORD, so to speak. It's just a clever way of compressing information into one variable.


int and long are the same in 32 bit processors, they are both 32 bit and hence Double Words (DWORD), unsigned short is 16 bit, single word (WORD), I think there us an quad word (64 bit), but I think its a struct of 2 DWORDs, the __int64 typedef is a bit missleading too, as it is really 32 bits in 32 bit architectures.

Cheers!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Kwizatz
int and long are the same in 32 bit processors, they are both 32 bit and hence Double Words (DWORD), unsigned short is 16 bit, single word (WORD), I think there us an quad word (64 bit), but I think its a struct of 2 DWORDs, the __int64 typedef is a bit missleading too, as it is really 32 bits in 32 bit architectures.

Cheers!


Actually Kwizatz, and integer is the size of the processor. Hence, an integer on a 8 bit processor is 8 bits, an integer on a 16 bit processor is 16 bits, and a integer on a 32 bit processor is 32 bits. Like wise, an integer on a 64 bit processor is 64 bits. The short and long data types are the same size on all processors.

The bad thing about using integers, is that there size is dependant on the system. One way that this would effect an application, is if the application where to use integers with file routines. Because one machine see an integer as a 64 bit data type and read 64 bits from the file stream. Were as, the host system that the application was designed on sees an integer as a 32 bit data type and will only read 32 bits of data. So bottom line is, never use an int unless you know you can get away with it.

Yes,Kwizatz, you are right! There is a 64 bit variable, but it is not a structure of two DWORDs. The Microsoft pacific version of this variable is __int64. The non Microsoft, or GCC definition is long long. Either of the two may be signed or unsigned. You will find that the size_t variable found in most standard C/C++ libraries, is in fact a 64 bit variable. A 64 bit integer is HUGE!

Share this post


Link to post
Share on other sites
SORRY! The AP was me. I though I put my un/pw in!? I guess not. Its a good thing that doesn't happen to often.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!