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

Home NTDEV

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: https://www.osr.com/osr-learning-library/


KMDF C++ support in 2022

j_hoppej_hoppe Member Posts: 2

Hi,

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 ...

<c-cpp-mix>

// 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;

WDF_DECLARE_CONTEXT_TYPE(MyDevice_CONTEXT);

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

</c-cpp-mix>

I was hoping for ...

<pure-cpp>

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

</pure-cpp>

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

Comments

  • 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
    OSR
    @OSRDrivers

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