18

I only have 32-bit Windows installed, so I cannot verify this myself.

If I understand correctly, the DWORD used in various places in the Microsoft API is in reference to the original 16-bit word, and has nothing to do with the current hardware architecture?

So DWORD which seems to be 32 bits, will remain 32 bits even when I eventually compile and link my app to run in 64-bit Windows? Or will DWORD become 128 bits wide?

Stéphane
  • 19,459
  • 24
  • 95
  • 136

5 Answers5

22

The only thing that changes size between 32 and 64 are pointers. So DWORD stays 32 bits wide.

Some things are not immediately obviously pointers, e.g. HANDLE, LPARAM, WPARAM. But these three change width as they actually hold pointers.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
3

DWORD is always 32 bits (unsigned). QWORD is always 64 bits (unsigned). Then there are the DWORD32 and a DWORD64 that are 32 and 64 bits. Don't ask me why are they there :-)

http://msdn.microsoft.com/en-us/library/cc230318(v=PROT.10).aspx

http://msdn.microsoft.com/en-us/library/cc230362(v=PROT.10).aspx

and in general

http://msdn.microsoft.com/en-us/library/cc230309(v=PROT.10).aspx

xanatos
  • 109,618
  • 12
  • 197
  • 280
2

Oh God, here comes another reasonable question... :)

It's always 32 bits, since a "word" is considered to be 16 bits in x86. Programs would break if the size changed.

If you need a native-size DWORD, try DWORD_PTR.

(Don't ask what the difference between DWORD_PTR, ULONG_PTR, UINT_PTR, and size_t is; I have no idea what Microsoft was thinking when it invented the first three...)

user541686
  • 205,094
  • 128
  • 528
  • 886
0

On x86 processors, a DWORD is 32 bits, even on 64-bit Windows. See this Wikipedia article.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
0

I would even go further than x86 arch. and say in general, a WORD may be considered to be 16 bits. The hierarchy traditionally has been BYTE (8 bits), WORD (16 BITS), and so a DWORD (if D is taken to be a double wide WORD) would be 32 bits. This doesn't necessarily have anything to do with a particular platform or language, a BYTE has been 8 bits and a WORD has been 16 bits going back to the old 8 bit computer days, even before the x86 arch. existed

hjorgan
  • 1
  • 1
  • 2
    A word was 32 bits on the mainframes long before x86 existed. – Bo Persson Jul 09 '11 at 12:30
  • A _byte_ is the smallest directly-addressable unit of memory. In all modern general-purpose processors, bytes have 8 bits. There were historically significant architectures with byte sizes of 6, 8, or 9 bits, which is why some standards use _octet_. A _word_ is the "natural unit" for the processor, typically the size of a general purpose register which was almost certainly also the size of an address. In modern processors, the word size is typically 8, 16, 32, or 64 bits, but there have been 36-bit machines. Intel chose to keep WORD fixed at 16 bits when rolling out 32-bit processors. – Adrian McCarthy Aug 14 '21 at 16:02