how to persist an information in the driver

I have a virtual hid driver that would talk to an application. Application would send some command say on or off. My driver needs to remember this state. later, if the application asks what state are you in , with a querydevice, my driver needs to reply with the last state. My driver is a dummy driver, it has no device or anything (forget this part, why the design is in this way, because we have a non hid serial device mapping which we have all is an another software solution).

either ways, my question is how can i persist this state, driver is stateless, in this case, what is the best way to solve the problem of storing this state somewhere.

I was thinking I could have another application that can be connected to the driver as well.

Application 1 sends a ON to the driver.
driver sends an output report to the Application 2.
Application 2 could save it
if Application 1 request for the state
driver now needs to request the state from Application 2 and get another input report
then pass it back to application 1.

but this is complicated and possible deadlocks / a lot of issues in this design…

why we need this -
application may send ON
later application wants to know if device is on or off
it may do a query to know if the device is on or off now
device needs to return the status of on / off.
but the virtual hid driver is dummy, it really doesnt have a device to store on / off or act on this . we just use the on / off signal to manipulate a serial device which works with our application

what is the simplest way to store and save states in the driver, assuming i have no hardware to store the state?

State persistence in the driver is not tied to physical hardware. Each pnp device stack has its own parameters key where you can store state, see WdfDeviceOpenRegistryKey and open the key with PLUGPLAY_REGKEY_DEVICE

1 Like

When you say “persist”, do you actually mean “persist across reboots”? Or do you just need it to survive during the current session? If you don’t need to survive reboots, then just store it in a global variable.

not accross reboot

not accross reboot

You know: We don’t charge you here based on the number of words in your posts.

You might be amazed at how much taking the time to clearly describe to us what you want to know would help us assist you.

Peter