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:

When is my first chance to access PLUGPLAY_REGKEY_DEVICE?

Wilhelm_NökerWilhelm_Nöker Member Posts: 47

Hi all,

in my virtual USB controller project, I've run into a problem related to the extended properties descriptor as it is used by modern WinUSB devices. The hard part where I am currently stuck, however, is just related to PnP and WDF, so I think that it doesn't take a dedicated USB expert to help me here.

Anyway, when WinUSB.sys gets loaded for a device, in its AddDevice routine it looks for a "DeviceInterfaceGUID" value in the device hardware key (the "Device Parameters" branch in the registry) which it passes on to WdfDeviceCreateDeviceInterface(). WinUSB client applications then can use SetupDiGetClassDevs( DIGCF_DEVICEINTERFACE ) to locate their device.

Now my responsibility as the (virtual) USB hub driver is to make sure that this registry value exists before WinUSB goes looking for it. But when do I do that? Right after WdfDeviceCreate() is too soon: WdfDeviceOpenRegistryKey( PLUGPLAY_REGKEY_DEVICE ) will return STATUS_INVALID_DEVICE_STATE. (It seems that the "Device Parameters" branch is not even created until the PnP system has selected a suitable driver for the first time.) And the device's EvtDevicePrepareHardware callback is too late: experiments tell me that it runs only after WinUSB's AddDevice routine.

So to summarize my question: When is my first chance to write to the registry hardware key of a device that I, as a bus driver, have just created myself? And is there even a standard callback available that will run at the right moment?


  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,996

    Hmmm... I don't think you're supposed to write that Registry key yourself.

    That key gets written as a result of calling IoRegisterDeviceInterface/WdfDeviceRegisterDeviceInterface, doesn't it??


    Peter Viscarola

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,714
    edited November 2021

    DeviceInterfaceGUID is a specific to WinUSB, but it does have a broadly applicable name that can lead you to believe it is used everywhere ;). IRP_MJ_PNP/IRP_MN_DEVICE_ENUMERATED tells the bus driver that the PDO it has reported previously is now a "real enough" PDO which as a devnode and can be passed as a PDO to APIs. Before this minor code was added, a bus driver had to infer when this state transition occurred. WDF does not appear to abstract this minor code with a callback, so you would need to add a preprocess callback for it when you create the PDO (WdfDeviceInitAssignWdmIrpPreprocessCallback)

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,348

    Originally, it was the responsibility of the driver writer to place that value in the INF file. However, if the device supports the "Microsoft OS Descriptors", then no INF is required, and the GUID is embedded in one of the extended descriptors. To be honest, I do not know which driver is responsible for transferring that info. If I had to guess, I'd guess it was the USB hub driver, since it's going to create that devnode. Are you using the standard hub driver, or have you written your own?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,996

    DeviceInterfaceGUID is a specific to WinUSB, but it does have a broadly applicable name that can lead you to believe it is used everywhere

    So, for the record (and the clarity of the OP), I stand corrected! "Never mind"...

    Thank you Doron and Tim.


    Peter Viscarola

  • Wilhelm_NökerWilhelm_Nöker Member Posts: 47

    Peter: Most of what IoRegisterDeviceInterface/WdfDeviceRegisterDeviceInterface do seems to take place in HKLM\System\CurrentControlSet\Control\DeviceClasses. But don't worry, I would never try to mess with that part of the registry directly.

    Tim: The hub driver is my own, too.

    Doron: IRP_MN_DEVICE_ENUMERATED seems to be exactly what I was looking for. Thanks!

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!
Writing WDF Drivers 12 September 2022 Live, Online
Internals & Software Drivers 23 October 2022 Live, Online
Kernel Debugging 14 November 2022 Live, Online
Developing Minifilters 5 December 2022 Live, Online