From: Freddie Witherden on
Hello,

I've been working on a WDF PnP driver which uses the
IOCTL_IEEE1394_API_REQUEST with IEEE1394_API_ADD_VIRTUAL_DEVICE to add
a virtual device. Assuming my driver is installed Windows will load
it and it will create a device interface. My program then uses
SetupDiEnumDeviceInterfaces and friends to find and open this handle.

My problem is as follows. The first time a virtual device is created
Windows takes a couple of seconds to delay-install the driver and
create the interface. All subsequent uses of the virtual device after
this are extremely quick. I want to know how my (library) code can
work around this. Always sleeping for two seconds or so is firstly
hacky, but also sub-optimal the second time my library is used (as the
interface is created quickly). Moreover, after waking up there is no
guarantee that a device interface will be created (such as if the
driver is not installed on the system).

How can my library do something along the lines of: "wait for an
interface if the driver is installed" otherwise to exit fast?
Repeatedly checking for new interfaces in a busy loop is also anything
but ideal (and again, may be in vain).

Finally, the virtual device created must be removed explicitly by user-
space with the IEEE1394_API_REMOVE_VIRTUAL_DEVICE IOCTL. However, if
a program using my library does not terminate correctly a virtual
device (and hence my driver and an interface) is left dangling. Is
there a means of cleaning up?
From: Maxim S. Shatskih on
> How can my library do something along the lines of: "wait for an
> interface if the driver is installed" otherwise to exit fast?

You can subscribe to interface arrival notification with WM_DEVICECHANGE.

> device (and hence my driver and an interface) is left dangling. Is
> there a means of cleaning up?

SetupDi APIs on the next app start.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: Pavel A. on
"Freddie Witherden" <freddie(a)witherden.org> wrote in message
news:9688b562-091b-429a-b6e8-8d12f2c5785b(a)q9g2000vbd.googlegroups.com...
> .................
> Finally, the virtual device created must be removed explicitly by user-
> space with the IEEE1394_API_REMOVE_VIRTUAL_DEVICE IOCTL. However, if
> a program using my library does not terminate correctly a virtual
> device (and hence my driver and an interface) is left dangling. Is
> there a means of cleaning up?

What bad could happen if the device is left behind after your app exited?
If nothing, you can just let it be; when the app runs again it will reuse
the device.
If you definitely must remove the device, make the driver detect that the
app
exited, for example, leave a pending ioctl. The driver will
receive cleanup when the app exits.

-- pa