Search code examples
c++windows-10portable-executable

Are Windows executables forward and backwards compatible?


Say I'm building a C++ portable executable and I include the windows.h header. Also, let's stick to just Windows 10. If I use the most recent Windows 10 Visual C++ toolchain to build the binary, can I run the binary on earlier versions of Windows 10? If I use the earliest Windows 10 Visual C++ toolchain to build the binary, can I run it on the latest version of Windows 10?

Let me know if you would like me to clarify the question.


Solution

  • Quoting from Microsoft's documentation under Update WINVER and _WIN32_WINNT.

    Visual Studio and the Microsoft C++ compiler support targeting Windows 7 SP1 and later.

    Older toolsets include support for Windows XP SP2, Windows Server 2003 SP1, Vista, and Windows Server 2008.

    Windows 95, Windows 98, Windows ME, Windows NT, and Windows 2000 are unsupported.

    Applications targeted at Windows 10 with the default #define's will run under all versions of Windows 10.

        #define WINVER       0x0A00
        #define _WIN32_WINNT 0x0A00
    

    To use newer APIs introduced in a later version of Windows 10, see the section under Remarks starting with "for a more fine-grained approach to versioning, you can use the NTDDI version constants in sdkddkver.h", and also the Using the Windows Headers page. For example, compiling with #define _WIN32_WINNT 0x0A00 and #define NTDDI_VERSION NTDDI_WIN10_19H1 will allow using features introduced in Windows 10 19H1, but only targets Windows 10 19H1 and later.