What is the smallest Windows header I can #include to define DWORD? What is the smallest Windows header I can #include to define DWORD? windows windows

What is the smallest Windows header I can #include to define DWORD?


Include Windows.h and use precompiled headers. Btw, you can define WIN32_LEAN_AND_MEAN and then undef it later!


I believe you used to be able to include winbase.h, but that doesn't seem to be the case anymore. All of the sources I've seen recommend windows.h, with the option of WIN32_LEAN_AND_MEAN. As you've indicated, the latter optimization doesn't help you.

You could do something like this.

#ifndef _WINDEF_typedef unsigned long DWORD;#endif

Not clean, but efficient. This typedef isn't likely to ever change.


A DWORD is always going to be a 32-bit unsigned int, so it doesn't really matter whether you use DWORD or unsigned long or uint32_t. If all three types refer to a 32-bit unsigned int, the compiler is going to consider them equivalent.

Since this is part of the platform-specific files, I don't think you need to worry about portability so much. Heck, dig into the headers to find the native type of a DWORD and just put that typedef in your header. C compilers accept duplicate typedefs as long as they have the same underlying type.