I. Definition
In VC6.0 's Microsoft Visual studio/vc98/include/windef.h, the Byte,word,dword is defined
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;
In Visual C + + 6.0, the char length is 1 bytes, the short length is 2 bytes, the int and long lengths are 4 bytes, so you can assume that byte and word,dword-defined variables have 1 bytes, 2 bytes, and 4 bytes of memory, respectively. is consistent with the literal meaning of byte and Word,dword.
That
byte=unsigned char (exact equivalent): 8 bits
word=unsigned short (completely equivalent): 16 bits
dword=unsigned long (completely equivalent): 32 bits
Here are some of the more commonly used macros:
Second, Window macros
1.LOBYTE (extract the Low-order byte from the given 16-bit value)
BYTE Lobyte (
WORD Wvalue//value from which low-order the byte is retrieved
);
#define Lobyte (W) ((BYTE) (W))
such as: WORD w=-0x1234;//w in memory in the complement form storage: 0XEDCC, that is, 0XCC (low address) 0xed (high address)
printf ("W Low byte:%x/n", Lobyte (w));//output: W Low byte: CC
2.HIBYTE (extract high byte from a given 16-bit value)
BYTE Hibyte (
WORD Wvalue//value from which high-order the byte is retrieved
);
#define Hibyte (W) ((WORD) (W) >> 8) & 0xFF)
such as: printf ("W's High Byte:%x/n", Hibyte (w));//output: W's high byte: Ed
3.LOWORD (extract low word from a given 32-bit value)
WORD LoWord (
DWORD dwvalue//value from which Low-order word is retrieved
);
#define LOWORD ((WORD) (L))
For example: DWORD l = 0x12345678;//l is stored in memory as: 0x78,0x56,0x34,0x12
printf ("L's low word:%x/n", LoWord (L));//output: L low word: 5678
4.HIWORD (extract high word from a given 32-bit value)
WORD HiWord (
DWORD dwvalue//value from which High-order word is retrieved
);
#define HIWORD (L) (WORD) ((DWORD) (L) >>) & 0xFFFF)
such as: printf ("L High word:%x/n", HiWord (L));//output: L's high word: 1234
5.MAKEWORD (concatenate two given unsigned character values into a 16-bit integer)
WORD Makeword (
BYTE BLow,//Low-order byte of short value
BYTE bhigh//High-order byte of short value
);
#define Makeword (A, B)/
((WORD) ((BYTE) (a)) | ((WORD) ((BYTE) (b))) << 8))
such as: BYTE blow=0x34,bhigh=0x12;
printf ("Makeword (%x,%x) =%x/n", Blow,bhigh,makeword (Blow,bhigh));
The output is: Makeword (34,12) =1234
6.MAKELONG (connecting two given 16-bit values into a 32-bit integer)
DWORD Makelong (
Word wlow,//Low-order Word of Long value
Word whigh//High-order Word of Long value
);
#define Makelong (A, B)/
(LONG) ((WORD) (a)) | ((DWORD) (WORD) (b)) << 16))
such as: WORD vlow=0x5678,vhigh=0x1234;
printf ("Makelong (%x,%x) =%x/n", Vlow,vhigh,makelong (Vlow,vhigh));
Output result: Makelong (5678,1234) =12345678