Bad version number checks

Raymond Chen

Version numbers. Very important. And so many people check them wrong.

This is why Windows 95’s GetVersion function returned 3.95 instead of 4.0. A lot of code checked the version number like this:

  UINT Ver = GetVersion();
  UINT MajorVersion = LOBYTE(uVer);
  UINT MinorVersion = HIBYTE(uVer);
  if (MajorVersion < 3 || MinorVersion < 10) {
   Error("This program requires Windows 3.1");
  }

Now consider what happens when the version number is reported as 4.0. The major version check passes, but the minor version check fails since 0 is less than 10.

This bug was so rife that we gave up shimming every app that had the problem and just decided, “Fine. If anybody asks, say that the Windows version is 3.95.”

I suspect this is also why DirectX always reports its version as 4.x.

0 comments

Discussion is closed.

Feedback usabilla icon