What is MAKEWORD used for?

I met this macro MAKEWORD(2,2)in a piece of tutorial code. I read on MSDN that it "creates a WORD value by combining the specified values."

The question is, this is not a WORD, something like unsigned integers, why would I ever need such a strange procedure as use MAKEWORD()?

+4
source share
2 answers

The macro expects two bytes as parameters:

WORD MAKEWORD(
  BYTE bLow,
  BYTE bHigh
);

Defined Windef.has:

#define MAKEWORD(a,b)   ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))

It basically builds 16-bit words from two 1-byte words (and doesn't look very portable)

Binary representation of 2 with 1 byte (WORD): | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |

, MAKEWORD(2,2), :

| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |

512 + 2 = 514: .

- Winsock, , WSAStartup.

+8

, MAKEWORD(x,y) ((y) << 8 | (x)); 16- , . LOBYTE HIBYTE, WORD.

16- Windows, , 32- . 16- Windows MSG wParam lParam, WORD LONG ; LONG.

, Windows, .

+1

Source: https://habr.com/ru/post/1543929/


All Articles