Convert Figma logo to code with AI

microsoft logoWindows-driver-samples

This repo contains driver samples prepared for use with Microsoft Visual Studio and the Windows Driver Kit (WDK). It contains both Universal Windows Driver and desktop-only driver samples.

6,865
4,904
6,865
439

Top Related Projects

This repo contains samples that demonstrate the API used in Windows classic desktop applications.

API samples for the Universal Windows Platform.

WDF makes it easy to write high-quality Windows drivers

Quick Overview

The microsoft/Windows-driver-samples repository is a collection of driver samples for the Windows operating system. It provides developers with practical examples and reference implementations for various types of Windows drivers, helping them understand best practices and accelerate their driver development process.

Pros

  • Comprehensive collection of driver samples covering a wide range of hardware and driver types
  • Official Microsoft repository, ensuring high-quality and up-to-date examples
  • Includes both user-mode and kernel-mode driver samples
  • Valuable resource for learning Windows driver development and understanding driver architecture

Cons

  • May require specific hardware or development environments to test certain samples
  • Some samples might be complex for beginners in driver development
  • Documentation for individual samples can vary in detail and quality
  • Requires a good understanding of Windows internals and driver concepts

Getting Started

To get started with the Windows driver samples:

  1. Clone the repository:

    git clone https://github.com/microsoft/Windows-driver-samples.git
    
  2. Install the Windows Driver Kit (WDK) and Visual Studio with the "Desktop development with C++" workload.

  3. Open the desired sample project in Visual Studio.

  4. Build the project and deploy it to a test machine or use the Windows Driver Framework (WDF) verifier for testing.

  5. Refer to the README file in each sample folder for specific instructions and requirements.

Note: Developing and testing drivers requires careful consideration of system stability and security. Always follow best practices and Microsoft's guidelines for driver development.

Competitor Comparisons

This repo contains samples that demonstrate the API used in Windows classic desktop applications.

Pros of Windows-classic-samples

  • Focuses on general Windows programming concepts and APIs
  • Covers a broader range of Windows development topics
  • Suitable for a wider audience of Windows developers

Cons of Windows-classic-samples

  • May not include the latest Windows features and APIs
  • Less specialized for hardware-specific development

Code Comparison

Windows-classic-samples:

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    wchar_t class_name[256];
    GetClassName(hwnd, class_name, 256);
    wprintf(L"Window handle: %p, class name: %s\n", hwnd, class_name);
    return TRUE;
}

Windows-driver-samples:

NTSTATUS
DriverEntry(
    _In_ PDRIVER_OBJECT  DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
{
    UNREFERENCED_PARAMETER(RegistryPath);
    DriverObject->DriverUnload = DriverUnload;
    return STATUS_SUCCESS;
}

The Windows-classic-samples code demonstrates a Windows API callback function for enumerating windows, while the Windows-driver-samples code shows a basic driver entry point function. This highlights the difference in focus between general Windows programming and driver development.

API samples for the Universal Windows Platform.

Pros of Windows-universal-samples

  • Focuses on Universal Windows Platform (UWP) app development, covering a wider range of application scenarios
  • More frequently updated, providing developers with current best practices and API usage examples
  • Includes samples for various Windows features like Cortana, Xbox Live, and Windows IoT

Cons of Windows-universal-samples

  • Limited to UWP development, not covering traditional Win32 or driver development
  • May require more recent versions of Windows for some samples to work properly
  • Less relevant for system-level or hardware-specific development tasks

Code Comparison

Windows-universal-samples (UWP app sample):

StorageFile file = await StorageFile.GetFileFromPathAsync(filename);
var stream = await file.OpenAsync(FileAccessMode.Read);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

Windows-driver-samples (Driver sample):

NTSTATUS
DriverEntry(
    _In_ PDRIVER_OBJECT  DriverObject,
    _In_ PUNICODE_STRING RegistryPath
    )
{
    // Driver initialization code
}

The code snippets demonstrate the difference in focus between UWP app development and low-level driver development.

WDF makes it easy to write high-quality Windows drivers

Pros of Windows-Driver-Frameworks

  • More focused on providing a structured framework for driver development
  • Offers higher-level abstractions and simplified APIs
  • Better suited for modern driver development practices

Cons of Windows-Driver-Frameworks

  • Less comprehensive in terms of sample variety
  • May have a steeper learning curve for beginners
  • Potentially less flexibility for low-level driver implementations

Code Comparison

Windows-driver-samples:

NTSTATUS
DriverEntry(
    _In_ PDRIVER_OBJECT  DriverObject,
    _In_ PUNICODE_STRING RegistryPath
)
{
    // Driver initialization code
}

Windows-Driver-Frameworks:

NTSTATUS
DriverEntry(
    _In_ PDRIVER_OBJECT  DriverObject,
    _In_ PUNICODE_STRING RegistryPath
)
{
    WDF_DRIVER_CONFIG config;
    WDF_DRIVER_CONFIG_INIT(&config, EvtDriverDeviceAdd);
    return WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
}

The Windows-Driver-Frameworks code demonstrates the use of WDF functions for driver initialization, showcasing its higher-level abstractions compared to the more traditional approach in Windows-driver-samples.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Driver samples for Windows 11

These are the official Microsoft Windows Driver Kit (WDK) driver code samples for Windows 11. They provide a foundation for Universal Windows driver support of all hardware form factors, from phones to desktop PCs. Use these samples with Visual Studio 2022 and Windows Driver Kit (WDK) 11.

Windows Driver Kit documentation

Windows 11 driver development

Use Visual Studio 2022 and Windows Driver Kit (WDK) 11 to build, test, and deploy your drivers. With Windows 11, the driver development environment is integrated into Visual Studio. To get started, download the driver development kits and tools for Windows 11.

Download the WDK, WinDbg, and associated tools

Windows Driver Kit (WDK)

Take a look at the compilation of the new and changed driver-related content for Windows 11. Areas of improvement include camera, print, display, Near Field Communication (NFC), WLAN, Bluetooth, and more.

Find out what's new in the WDK

Universal Windows drivers

Write one driver that runs on Windows 11 for desktop editions, as well as other Windows editions that share a common set of interfaces.

Getting Started with Universal Windows drivers

Windows Driver Frameworks

The Windows Driver Frameworks (WDF) are a set of libraries that make it simple to write high-quality device drivers.

WDF driver development guide

Samples

Use the samples in this repo to guide your Windows driver development. Whether you're just getting started or porting an older driver to the newest version of Windows, code samples are valuable guides on how to write drivers.

For information about important changes that need to be made to the WDK sample drivers before releasing device drivers based on the sample code, see the following topic:

From Sample Code to Production Driver - What to Change in the Samples

Build your first driver

If you're writing your first driver, use these exercises to get started. Each exercise is independent of the others, so you can do them in any order.

Write a UMDF driver based on a template

Write a KMDF Hello World driver

Write a KMDF driver based on a template

Use GitHub Actions to build a simple driver project

Microsoft Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.