Search code examples
c++visual-c++wtl

What options do I have to build a WTL program that runs on XP and later but with latest features?


By default WTL uses defines to make features available according to the WINVER etc, much like windows.h and other Windows SDK headers, really.

This means a modern WTL application when linked can only run on XP and later, but uses exclusively the features available to XP. If you include features from newer platforms you end up with a binary that's incompatible with XP.

Is there a way to build a WTL application in such a way that on new systems it will have the modern appearance (modern common controls and common dialogs) while it can still run on XP? How would I go about that?


Solution

  • Inability to run in XP and pre-XP systems comes from using latest Visual C++ toolsets, rather than use of recent WINVER values. The last C++ runtime compatible with Windows 2000 is, as far as I remember, Visual Studio 2008's "v90" - this is what you need to use (or, non-MS compiler alternatively?). For XP, you need one of the toolsets: v100, v110_xp, v120_xp. Note that "_xp" suffix means that this is alternate version of another mainstream toolset, which is however incompatible with XP.

    That is, to target XP and on, you need a proper toolset and then version of Visual Studio and inclusion or non-inclusion of latest WINVERs don't matter.

    Current release of WTL and Visual Studio versions 2008 through 2013 with proper toolset applied build valid XP compatible applications, which in the same time might include most recent SDK definitions, unlocked to you by high WINVER values.

    The application built this way is compatible with OS versions in terms of not having static links to possibly missing dependencies. The other way, it is up you to to detect if specific feature is available in the runtime environment. For instance, if you are going to use features which require Common Controls version 6 and they are missing in XP, then you are responsible to check available features and fall back to respective code path in your code.