User-Mode Driver Framework (UMDF)

The User-Mode Driver Framework (UMDF) is a set of COM interfaces and services that enable you to write and deploy drivers that run in user mode. UMDF simplifies driver development by providing a framework that handles many common driver tasks, allowing you to focus on device-specific functionality.

What is UMDF?

UMDF provides a robust and simplified environment for developing drivers. By running drivers in user mode, UMDF enhances system stability and security. If a user-mode driver encounters an error, it is less likely to crash the entire operating system compared to a kernel-mode driver.

Key Benefits of UMDF:

Getting Started with UMDF

To begin developing UMDF drivers, you'll need to set up your development environment. This typically involves installing the Windows Driver Kit (WDK) and Visual Studio. The WDK provides the necessary tools, headers, libraries, and samples for driver development.

Essential Components:

Refer to the Driver Development Environment documentation for detailed setup instructions.

UMDF Architecture

UMDF consists of the UMDF host process and the UMDF driver. The host process (WUDFHost.exe) acts as a mediator between the UMDF driver and the operating system. When a device is connected, the UMDF host process is launched, and your UMDF driver is loaded into this process.

The UMDF host process manages the lifecycle of UMDF drivers and handles inter-process communication, ensuring that individual drivers do not interfere with each other or the system kernel.

Developing a UMDF Driver

Developing a UMDF driver involves implementing COM interfaces that the framework exposes. Key aspects include:

Example of an I/O Request:

When an application sends an I/O request to your device, the UMDF framework receives it and forwards it to your driver. Your driver's implementation of the IWDFIoQueue::OnIoDefault (or a more specific handler) method will be invoked.


// Example: Simplified handler for an I/O request
HRESULT MyDevice::OnIoDefault(IWDFIoQueue* pWdfQueue, IWDFIoRequest* pWdfRequest)
{
    ULONG IoControlCode;
    pWdfRequest->GetIoControlCode(&IoControlCode);

    switch (IoControlCode)
    {
        case IOCTL_MY_CUSTOM_COMMAND:
            // Handle custom command
            break;
        case IOCTL_READ_DATA:
            // Handle read request
            break;
        default:
            // Unrecognized I/O control code
            pWdfRequest->CompleteWithInformation(
                HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION),
                0);
            return S_FALSE; // Request processed
    }

    // If handled, complete the request
    return S_OK;
}
            

UMDF Samples

The WDK includes numerous sample UMDF drivers that demonstrate various device types and functionalities. These samples are an excellent resource for learning how to implement specific features and understand the UMDF programming model.

Explore the UMDF samples in the WDK installation directory or on the GitHub repository for comprehensive examples.