Develop Windows kernel-mode drivers using C++ and STL
Windows kernel-mode drivers have been traditionally developed using C programming language. Usage examples, existing frameworks and APIs usually imply C.
However, Windows kernel-mode drivers not only may be developed using C++ (including latest language standards, like C++23), but may also use large portion of standard library, including STL. WDM and KMDF drivers can easily include the following STL headers and use most of the classes and functions defined in them:
* `<memory>`: `std::unique_ptr`, including `std::make_unique_*`...
* `<array>`
* `<atomic>`
* `<algorithm>`
* `<ranges>`
* `<chrono>`
* `<type_traits>`
* `<concepts>`
* `<string_view>`
* `<utility>`: `std::exchange`, `std::move`, `std::swap`, `std::pair` …
* `<tuple>`
* `<optional>`
* `<variant>`
* `<bit>`
* `<span>`
* `<expected>`
* `<mutex>`
* `<coroutine>` - yes, you can even use coroutines in kernel-mode driver!
Additionally, the following libraries have been successfully used from Boost:
* `variant2`
* `intrusive_ptr`
* Some containers from Boost.Container
The [following repository](https://github.com/AlexBAV/cppindriver) provides a small C++ framework library and illustrates how it can be used to create a WDM function and WDM filter drivers.
The library and the article also show how using modern C++ with STL allows a much safer approach for developing kernel-mode drivers: use RAII and automatic memory management to forget about memory and resource leaks.
Simplify asynchronous request processing with coroutines and remove a burden of request cancellation handling with a convenient C++ wrapper for Cancel-Safe queues.
https://redd.it/1ok5hso
@r_cpp
Post #24142
13