Kernel-Mode Driver Framework (KMDF)

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

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.

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.