Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IoCreateDevice() - Only in DriverEntry ?

0 views
Skip to first unread message

Philip Boucherat

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
Hi,

I'm wondering if it's possible for a driver to create new devices at any
time other than during the DriverEntry() routine, say for example during
Ioctl processing? The reason is that the devices exist on the network
and may or may not be switched on when the driver is loaded, so I'd have
an app send an Ioctl to the driver every now and then to tell it to look
for new devices, at which point the driver would have to call
IoCreateDevice() using the DriverObject pointer that was passed to
DriverEntry() - maybe that wouldn't be valid any more. I don't know.

Cheers,

Phil
--
Philip Boucherat

eli...@microsoft.com

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
In article <3dCt7DAv...@teccon.co.uk>,

You can call IoCreateDevice in any routine you want as long as the
routine runs at PASSIVE_LEVEL. If you create deviceobject in routines
other than DriverEntry, you must clear the DO_DEVICE_INITIALIZING flag
(deviceObject->Flags &= ~DO_DEVICE_INITIALIZING) of the deviceobject.
Otherwise, you wouldn't be able to open an handle to the device.

-Eliyas

Sent via Deja.com http://www.deja.com/
Before you buy.

Jamey kirby

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
Yes you can. You MUST reset the initilization bit manualy if you create the
device object outside DriverEntry((.

DeviceObject->Flags &= ~ DO_INITIALIZING;

Jamey Kirby
jki...@storagecraft.com

Matt A.

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
Matt A. wrote in message <814jng$93t$1...@news.ime.net>...

[snip]

>The DRIVER_OBJECT pointer passed to DriverEntry() remains valid until you
>driver is unloaded. If you need it after DriverEntry(), simply save it in
>a global variable (just like saving a copy of the HINSTANCE passed to
>WinMain() in a Windows program).

Oh yeah, if you create a DEVICE_OBJECT(s) during DriverEntry(), you can
also access your driver object pointer later on via that(those) device
object('s) conveniently-named 'DriverObject' pointer.

[snip]


Best regards,

Matt Arnold
Professional Music Products
Mark of the Unicorn, Inc.
http://www.motu.com

In an attempt to foil spammers I use a "fake" e-mail address when posting
to newsgroups. Replace "biteme" with "motu" to obtain my actual address.

*-----------------------------------------------------------------------*
| N O T I C E T O S P A M M E R S |
| |
| Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227 any |
| and all unsolicited commercial e-mail sent to this address is subject |
| to a download and archival fee in the amount of US$500.00. E-MAILING |
| THIS ADDRESS DENOTES ACCEPTANCE OF THESE TERMS. For more information |
| go to http://thomas.loc.gov/cgi-bin/bdquery/z?d105:SN01618:@@@D. |
| |
*-----------------------------------------------------------------------*


Matt A.

unread,
Nov 19, 1999, 3:00:00 AM11/19/99
to
Philip Boucherat wrote in message <3dCt7DAv...@teccon.co.uk>...

>Hi,
>
>I'm wondering if it's possible for a driver to create new devices at any
>time other than during the DriverEntry() routine, say for example during
>Ioctl processing? The reason is that the devices exist on the network
>and may or may not be switched on when the driver is loaded, so I'd have
>an app send an Ioctl to the driver every now and then to tell it to look
>for new devices, at which point the driver would have to call
>IoCreateDevice() using the DriverObject pointer that was passed to
>DriverEntry() - maybe that wouldn't be valid any more. I don't know.

Well, WDM drivers create new DEVICE_OBJECTs all the time "outside" of
DriverEntry() -- in AddDevice() for example. So, clearly, a WDM driver is
not limited to creating new devices in DriverEntry(). That same is
actually true for "regular" NT (non-WDM) drivers as well.

Generally, a driver can create new DEVICE_OBJECTs at any time -- so long as
it's running at PASSIVE_LEVEL (a requirement of calling IoCreateDevice()).
As IOCTL processing usually takes place at PASSIVE_LEVEL, it would be
perfectly reasonable to create a new device(s) in response to such a
request.

The DRIVER_OBJECT pointer passed to DriverEntry() remains valid until you
driver is unloaded. If you need it after DriverEntry(), simply save it in
a global variable (just like saving a copy of the HINSTANCE passed to
WinMain() in a Windows program).

Finally, there is one caveat to creating DEVICE_OBJECTs outside of
DriverEntry() -- you must clear each such device's DO_INITIALIZING flag
manually. This flag is cleared automatically for all devices created
*before* DriverEntry() returns, but *not* those created after.

0 new messages