April 10th, 2007

What is the default version of a header file?

The general rule with Windows header files is that if you don’t specify which version of the header file you want, you get the latest version. For example, if you have the Windows XP Platform SDK header files and you #include <windows.h>, you’re going to get the Windows XP function prototypes, the Windows XP structures, the the Windows XP flags, all that stuff. And unless you’re careful, the program you get as a result will most likely run only on Windows XP.

If you call a function that is new for Windows XP, then your program won’t run on earlier versions of Windows because the import can’t be resolved.†

If you use a structure that changed for Windows XP, then your program won’t run on earlier versions of Windows because the structure size will be wrong.

Even if the structure size didn’t change, using a flag that was introduced in Windows XP will create difficulties for your program when run on earlier versions of Windows because those earlier versions don’t support the flag you’re passing. Depending on how the function in question was written, it may ignore the “flag from the future” or it may reject it as invalid.

If you want your program to run on older versions of Windows, you have a few options. First, you can explicitly “downgrade” your header file by defining an appropriate symbol or symbols before including the windows.h header file.

#define WINVER         0x0400
#define _WIN32_WINNT   0x0400
#define _WIN32_WINDOWS 0x0400
#define _WIN32_IE      0x0400
#include <windows.h>
#include <commctrl.h>
#include <shlobj.h>
...

Oh yuck, now we have the messy world of “So what’s the difference between _WIN32_WINNT, _WIN32_WINDOWS, _WIN32_IE, and WINVER?” We’ll pick up this topic next time, but you’re not going to like the answer.

Nitpicker’s corner

†That statement is from the operating system’s‡ point of view. You can of course use techniques like Visual Studio linker’s delay-load feature to avoid creating an import dependency, but that’s outside the operating system.‡

‡s/operating system/Windows operating system/

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.