Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

KMDF C++ support in 2022

j_hoppej_hoppe Member Posts: 2


At the moment I'm porting a driver from C to C++ (which has been C++ in the old days of Compuware Driver::Works).

Work is done, but the interface to KMDF callbacks still looks clumsy.

At the moment I have a C/C++ mix like ...


// All Logic in my class
class MyDevice {
    NTSTATUS   EvtDeviceD0Entry(IN WDF_POWER_DEVICE_STATE PreviousState) ;
} ;

// The WDF DeviceContext just contains my device 
typedef struct  {
    MyDevice    mydevice ; // context wraps class
} MyDevice_CONTEXT;


// The Wdf callbacks are just a wrappers to methods of my device
NTSTATUS        MyDevice__EvtDeviceD0Entry( IN WDFDEVICE wdfDevice,
    MyDevice *mydevice = &(WdfObjectGet_MyDevicee_CONTEXT(wdfDevice)->mydevice) ;
    return mydevice->EvtDeviceD0Entry(PreviousState) ;


I was hoping for ...


// WDF defines adevice base class "WdfDevice"
class MyDevice: WdfDevice {
    // mydevice implements the D0Entry callback
    virtual NTSTATUS   EvtDeviceD0Entry(IN WDF_POWER_DEVICE_STATE PreviousState) ;


I remember seeing some MicroSoft docs showing C++ code examples, but somehow my Google Bubble is supressing these now.

I'd be happy to have a doc explaining current and future C++ support in KMDF.

thanks and kind regards,

Joerg Hoppe


  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,046

    Though written in (a highly restrained variant of) C++, KMDF provides a C Language interface to match the rest of the Window OS.

    KMDF is mature, being more than 15 years old, and to the best of my knowledge there are no future plans to drastically change the interface. The old version of UMDF has a C++ interface based on the COM programming model, but this predictably proved… ah… “unpopular” for a long list of reasons.

    I’m far more familiar with DriverWorks than I’d prefer to be, and… My best suggestion to you is not to propagate the mess that you have, and instead rewrite your driver as a proper KMDF driver… in proper C or using modern C++ as a better C.

    Peter Viscarola

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 January 2023 Live, Online
Developing Minifilters 20 March 2023 Live, Online
Writing WDF Drivers TBD 2023 Live, Online
Internals & Software Drivers 17 April 2023 Live, Online