Table of contents
TOC
Collapse the table of content
Expand the table of content

Building Drivers for Different Versions of Windows

Last Updated: 7/30/2016

If you are writing drivers for different versions of Windows, the following section provides some guidelines about how you should build those drivers using the Windows Driver Kit (WDK) 8.1 or WDK 8, Visual Studio, and MSBuild.

Guidelines that apply to building both user-mode and kernel-mode drivers

  • Build your drivers using the target configurations and platforms that the WDK provides. Always use the latest version of the WDK that supports the version of Windows that you want to target. For example, to build drivers for Windows XP, you must use the Windows 7 WDK. But if you are building a driver for Windows 8.1, Windows 8, Windows 7, use the WDK 8.1 and Visual Studio.
  • If your driver must run only on a single version of Windows, build the driver for the target configuration and platform that matches your target Windows version. For example, if you are building a driver that will run only on WDK 8.1, specify Win8.1 in the Configuration Manager.
  • If you want your driver to run on multiple versions of Windows, but without features that are available only on newer versions, build the driver for the oldest version that you want the driver to support. For example, if your driver will run on all Windows versions starting with Windows Vista and it will use only features that are provided on Windows Vista, specify Vista for the project configuration.

Guidelines that apply to building kernel-mode drivers

  • If you want your kernel-mode driver to run on multiple versions of Windows and dynamically determine the features that are available to the driver, build the driver using the build configuration for the most recent version of the operating system. For example, if you want your driver to support all versions of Windows starting with Windows 7, but to use certain features that were first available in Windows 8.1 when your driver is running on Windows 8.1 or later versions of the operating system, specify Windows 8.1 (Win8.1) as the target configuration.

  • Use the RtlIsNtDdiVersionAvailable and RtlIsServicePackVersionInstalled functions to determine the version of Windows that is available to your driver at run time. For more information, see Writing drivers for different versions of Windows.

  • Create prototypes for pointers to functions that your driver must call conditionally.
  • If you have a WDM driver, or a non-KMDF kernel-mode driver, and you are targeting Windows 8.1 or Windows 8 but also want to run on earlier versions of Windows, you need to override the linker $(KernelBufferOverflowLib) option. When you select Windows 8 or Windows 8.1 configurations, the driver is linked with BufferOverflowFastFailK.lib, which is not available in earlier Windows versions. For Windows 7 and Vista, you must link with BufferOverflowK.lib instead.

    There are two ways to override the $(KernelBufferOverflowLib) linker option, using either MSBuild or Visual Studio.

    Using MSBuild:

    msbuild /p:KernelBufferOverflowLib="C:\Program Files (x86)\Windows Kits\8.1\Lib\win8\km\x64\BufferOverflowK.lib" /p:platform=x64 /p:Configuration="Win8 Release" myDriver.sln
    

    Using Visual Studio:

    Using Notepad, or another text editor, open the driver project file (*.vcxproj). In the project file, locate the <PropertyGroup> for the configurations your driver supports, and add the following line to override the default linker option:

    XML
     
       <KernelBufferOverflowLib>$(DDK_LIB_PATH)\BufferOverflowK.lib</KernelBufferOverflowLib>
    

    For example, if your driver supports Windows 8.1 and Windows 8 debug and release builds, those configuration sections would look like the following:

    XML
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8.1 Debug|Win32'" Label="Configuration">
        <TargetVersion>WindowsV6.3</TargetVersion>
        <UseDebugLibraries>true</UseDebugLibraries>
        <KernelBufferOverflowLib>$(DDK_LIB_PATH)\BufferOverflowK.lib</KernelBufferOverflowLib>
        <PlatformToolset>WindowsKernelModeDriver8.1</PlatformToolset>
        <ConfigurationType>Driver</ConfigurationType>
        <DriverType>KMDF</DriverType>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8.1 Release|Win32'" Label="Configuration">
        <TargetVersion>WindowsV6.3</TargetVersion>
        <UseDebugLibraries>false</UseDebugLibraries>
        <KernelBufferOverflowLib>$(DDK_LIB_PATH)\BufferOverflowK.lib</KernelBufferOverflowLib>
        <PlatformToolset>WindowsKernelModeDriver8.1</PlatformToolset>
        <ConfigurationType>Driver</ConfigurationType>
        <DriverType>KMDF</DriverType>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Debug|Win32'" Label="Configuration">
        <TargetVersion>Windows8</TargetVersion>
        <UseDebugLibraries>true</UseDebugLibraries>
        <KernelBufferOverflowLib>$(DDK_LIB_PATH)\BufferOverflowK.lib</KernelBufferOverflowLib>
        <PlatformToolset>WindowsKernelModeDriver8.1</PlatformToolset>
        <ConfigurationType>Driver</ConfigurationType>
        <DriverType>KMDF</DriverType>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win8 Release|Win32'" Label="Configuration">
        <TargetVersion>Windows8</TargetVersion>
        <UseDebugLibraries>false</UseDebugLibraries>
        <KernelBufferOverflowLib>$(DDK_LIB_PATH)\BufferOverflowK.lib</KernelBufferOverflowLib>
        <PlatformToolset>WindowsKernelModeDriver8.1</PlatformToolset>
        <ConfigurationType>Driver</ConfigurationType>
        <DriverType>KMDF</DriverType>
      </PropertyGroup>

    The <KernelBufferOverflowLib> elements must appear in the driver project file before the element that imports Microsoft.Cpp.props, which imports the tool set.

    After you modify and save the driver project file, you can open the project file in Visual Studio and build the driver.

© 2017 Microsoft