Introduction
The Kernel-Mode Driver Framework (KMDF) provides a standard set of libraries and tools to simplify the development of Windows kernel-mode drivers. KMDF abstracts the low‑level interactions with the OS, allowing developers to focus on device‑specific logic.
Key Features
- Object‑oriented driver model
- Power management support
- Plug‑and‑play handling
- Automatic IRP forwarding
- Rich debug and tracing infrastructure
Architecture Overview
KMDF is built on top of the Windows Driver Model (WDM). It introduces
driver objects such as WDFDRIVER, WDFDEVICE,
WDFQUEUE, and WDFIOQUEUE. Each object encapsulates
functionality and state, reducing boilerplate code.
// Simplified object hierarchy
WDFDRIVER
└─ WDFDEVICE
├─ WDFQUEUE (I/O)
└─ WDFTIMER (timers)
// Each object has a context area for driver‑specific data.
Hello World Sample
Below is a minimal KMDF driver that creates a device and logs a message when the driver loads.
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD EvtDeviceAdd;
NTSTATUS
DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
WDF_DRIVER_CONFIG config;
WDF_DRIVER_CONFIG_INIT(&config, EvtDeviceAdd);
return WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
}
NTSTATUS
EvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
UNREFERENCED_PARAMETER(Driver);
KdPrint(("KMDF Hello World: Device added\n"));
return STATUS_SUCCESS;
}
Development Tools
Microsoft Visual Studio provides integrated support for KMDF development. Use the KMDF Library Templates to generate driver scaffolding.
- WDK (Windows Driver Kit) – version 10.0.22621.0
- Visual Studio 2022 – C++ development workload
- WinDbg – kernel debugging
FAQ
- Is KMDF mandatory for new drivers?
- While not mandatory, KMDF is the recommended framework for new kernel‑mode drivers due to its robustness and long‑term support.
- Can I mix KMDF and WDM code?
- Yes, KMDF is built on top of WDM, and you can intermix WDM calls when necessary.