Unloading KMDF Control Device driver

Hi,

I have a problem several times mentioned before:
How can I unload a KMDF driver which implements a Control Device?

In Device Manager I can “deactivate” and the visual device state changes,
however the driver is not unloaded, nor receives DriverEvtDriverUnload().
Also devcon says: “disable failed”, resp. “remove failed”.

The device is created with
DriverEntry() {

deviceInit = WdfControlDeviceInitAllocate(driver, &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R);

WdfDeviceCreate( &deviceInit, &deviceAttributes, &controlDevice) ;

}

The driver is not used by any application.
No file handles are open to the driver.
The driver does not load on boot time, Start type is 3 “on demand”.

I’ve read I should WdfDeleteObject(controlDevice) before unloading,
but how to trigger this from device manager or devcon or other application?

Any hints or links? Perhaps for a list of things to check?

thanks,

Joerg Hoppe
PEAK System Technik

The control device needs to be deleted when the last pnp device is removed. As a corollary you should create the control device after the first pnp device is created.

Dolon,
thanks for caring.
My problem here: This driver only implements an IoCtl interface, no further pnp objects.
ioQueueConfig.EvtIoDeviceControl = My_EvtIoDeviceControl;
So I don’t have events to delete the ControlDevice itself … Only possibility would be a self-destructing IoCtl call?

Background: we have a family of network controller drivers, all with same API.
This driver is a “virtual demo stub” to let customer learn our API without actual devices.

regards,
Joerg

Ok so you do not have any pnp devices, so this is a software only driver. The short answer is that if you code it correctly WDF will do everything for you and you can start /stop your driver from user mode and it will clean itself up. See https://github.com/microsoft/Windows-driver-samples/tree/main/general/ioctl/kmdf/sys - I think this sample is exactly what you want.