What is the smallest Windows header I can #include to define DWORD?
c, header, windows
Solution
Include Windows.h and use precompiled headers. Btw, you can define WIN32_LEAN_AND_MEAN and then undef it later!
Problem
I have a small header file of my own which declares a couple of functions, one of which has a return type of `DWORD`. I'm reluctant to drag in `windows.h` just to get the official definition of this type since that file is huge, and my header will be used in a number of source modules that don't otherwise need it. Of course, in practice I know that `DWORD` is just `unsigned int`, but I'd prefer the more hygienic approach of including an official header file if possible. On this page it says that `DWORD` is defined in `windef.h`, but unfortunately including just this small file directly leads to compilation errors -- apparently it expects to be included by other headers. (Also, the fact that my file is a header file also means I can't just declare `WIN32_LEAN_AND_MEAN`, since the source file that #includes my file might need this to be left undefined.) Any ideas? I know it's not the end of the world -- I can just continue to `#include <windows.h>` -- but thought someone might have a better idea! [EDIT] Thanks for your responses. To those who suggested using a different type, let me explain why that's not desirable in this case: I've set up different, platform-specific versions of the two functions in different source files, and ask the CMake configuration to detect the current platform and choose which one to build. On Windows, my functions look like: ``` typedef DWORD TimePoint; TimePoint GetTimeNow(void); double TimeDifference(TimePoint start, TimePoint end); ``` The Windows version of `GetTimeNow()` just calls the Windows API `timeGetTime()`, which has return type `DWORD`, and so it must have the same return type. (On other platforms, `TimePoint` will have a different type, e.g. `struct timeval` on UNIXy platforms.) In effect, values of type `TimePoint` are opaque, and the only thing you can do with them is pass two of them to `TimeDifference()` to measure the elapsed time between them in seconds. This enables cross-platform development. Unfortunately it still means that client code has to know the concrete type of `TimePoint`.