Question

in WinAPI:

typedef unsigned long DWORD;

I think DWORD, WORD ... is the basic data type in computer, for no matter int, unsigned long... it will be converted to DWORD finally in assembly, why should it be converted to unsigned long here? Can't I use DWORD directly without the difinition?

Was it helpful?

Solution

DWORD is whatever it is defined to be (there is no automatic translation to a specific width in assembly). This typedef is needed because the WinAPI interfaces are all defined with unsigned longs wherever DWORD is used. IOW, you need this definition in place to work with the API.

To answer your other question. This answer is no, DWORD can't be used without a definition. It isn't a built-in type for the compiler.

The definition of DWORD is fixed for the Win32 API: http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx

OTHER TIPS

In the Windows API and in assembly languages based on the x86 instruction set, DWORD designates a variable with a size of 32 bits. So yes, it usually is the same size.

You can't use the type DWORD in C++ without defining it because it is not part of the core language. The type definition of DWORD may need to be adjusted depending on your compiler and system architecture. Apparently, for your configuration, the type unsigned long has 32 bits, so DWORD is defined as unsigned long.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top