Have you ever wondered if a Windows driver can detect the version of the Windows SDK (Software Development Kit) or Windows Driver Kit (WDK) that was used to build it? The answer is yes, it can! In this article, we will explain how a Windows driver can detect its build Windows Kit and why it might be useful for developers and support engineers.
What is the Windows Driver Kit?
The Windows Driver Kit (WDK) is a set of tools, drivers, and documentation that developers can use to build, test, and deploy Windows drivers. The WDK includes a compiler, a linker, and other tools that are used to build and debug drivers. The WDK also includes a set of header files that define the Windows driver model and the APIs that are used to interact with the operating system.
Why would a Windows driver need to detect its build Windows Kit?
There are several reasons why a Windows driver might need to detect its build Windows Kit. One reason is that different versions of the WDK may include different versions of the Windows driver model, the APIs, and the tools. By detecting the build Windows Kit, a driver can determine the version of the driver model and the APIs that it was built with, which can be useful for debugging and testing.
Another reason why a Windows driver might need to detect its build Windows Kit is that the driver may need to use features or APIs that are only available in certain versions of the WDK. By detecting the build Windows Kit, a driver can determine if the required features or APIs are available and can use them if they are. If the required features or APIs are not available, the driver can take appropriate action, such as logging an error message or failing to load.
How can a Windows driver detect its build Windows Kit?
A Windows driver can detect its build Windows Kit by using the NTDDI_VERSION macro. The NTDDI_VERSION macro is defined in the ntddk.h header file and is used to specify the version of the Windows driver model that the driver is built with. The NTDDI_VERSION macro is defined as follows:
#define NTDDI_VERSION 0x06000000
The value of the NTDDI_VERSION macro is a bitmask that specifies the version of the Windows driver model. The version number is represented as a hexadecimal value, where the first two digits represent the major version number and the last four digits represent the minor version number. For example, the value of NTDDI_VERSION for Windows Vista and later is 0x06000000, where the major version number is 6 and the minor version number is 0.
To detect the build Windows Kit, a Windows driver can use the NTDDI_BUILD macro. The NTDDI_BUILD macro is defined in the ntddk.h header file and is used to specify the version of the Windows SDK or WDK that was used to build the driver. The NTDDI_BUILD macro is defined as follows:
#define NTDDI_BUILD 0x06010000
The value of the NTDDI_BUILD macro is also a bitmask, where the first two digits represent the major version number of the Windows SDK or WDK and the last four digits represent the minor version number. For example, the value of NTDDI_BUILD for the Windows SDK for Windows 8.1 and the WDK for Windows 8.1 is 0x06010000, where the major version number is 6 and the minor version number is 1.
To detect the build Windows Kit, a Windows driver can use the following code:
#if (NTDDI_VERSION >= NTDDI_WIN8)
if (NTDDI_VERSION >= NTDDI_BUILD)
{
// The driver was built with the WDK for Windows 8.1 or later.
}
else
{
// The driver was built with the WDK for Windows 8.
}
#else
// The driver was built with an earlier version of the WDK.
#endif
The code uses the NTDDI_VERSION macro to determine the version of the Windows driver model that the driver is built with. If the driver is built with the Windows driver model for Windows 8 or later, the code uses the NTDDI_BUILD macro to determine the version of the Windows SDK or WDK that was used to build the driver. If the driver is built with an earlier version of the Windows driver model, the code takes appropriate action, such as logging an error message or failing to load.
In this article, we have explained how a Windows driver can detect its build Windows Kit. By using the NTDDI_VERSION and NTDDI_BUILD macros, a driver can determine the version of the Windows driver model and the version of the Windows SDK or WDK that it was built with. This information can be useful for debugging, testing, and using features or APIs that are only available in certain versions of the Windows SDK or WDK.
References
| Title | Description | URL |
|---|---|---|
| Windows SDK | The Windows SDK is a set of tools, drivers, and documentation that developers can use to build Windows applications. The Windows SDK includes the Windows Driver Kit (WDK), which is a set of tools, drivers, and documentation that developers can use to build Windows drivers. | https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/ |
| Windows Driver Kit (WDK) | The Windows Driver Kit (WDK) is a set of tools, drivers, and documentation that developers can use to build, test, and deploy Windows drivers. The WDK includes a compiler, a linker, and other tools that are used to build and debug drivers. The WDK also includes a set of header files that define the Windows driver model and the APIs that are used to interact with the operating system. | https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk |
| Windows Driver Model | The Windows Driver Model (WDM) is a framework that provides a set of APIs and services that Windows drivers can use to interact with the operating system. The WDM includes a set of rules and guidelines that drivers must follow to ensure that they are compatible with the operating system and with other drivers. | https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/windows-driver-model-overview |