Hi, in Walter Oney’s book: Programming the Microsoft
Windows Driver Model, Second Edition, Chapter 5,
Summary—Eight IRP-Handling Scenarios, Scenario 5—Your
Own Asynchronous IRP, there is the following
information:
The calls to ObReferenceObject and ObDereferenceObject
that precede and follow the call to IoCallDriver (the
points labeled B) are necessary only when you’ve used
IoGetDeviceObjectPointer to obtain the DeviceObject
pointer and when the completion routine (or something
it calls) will release the resulting reference to a
device or file object.
My question is why I need to do this ObReferenceObject
and ObDereferenceObject once I got the DeviceObject by
IoGetDeviceObjectPointer. MUST I do this?
Thanks
Michael
Post your free ad now! http://personals.yahoo.ca
If the PnP manager decides to do its thing, you need some way to keep your
driver and the driver you called in memory until the IRP is completed. You
can use either B or A, but not both. The reference when you got the device
object pointer will be released when your unload routine is called, so you
don’t want the reference count to go to zero before the IRP completes.
“Michael Zhu” wrote in message news:xxxxx@ntdev…
>
> Hi, in Walter Oney’s book: Programming the Microsoft
> Windows Driver Model, Second Edition, Chapter 5,
> Summary-Eight IRP-Handling Scenarios, Scenario 5-Your
> Own Asynchronous IRP, there is the following
> information:
>
> The calls to ObReferenceObject and ObDereferenceObject
> that precede and follow the call to IoCallDriver (the
> points labeled B) are necessary only when you’ve used
> IoGetDeviceObjectPointer to obtain the DeviceObject
> pointer and when the completion routine (or something
> it calls) will release the resulting reference to a
> device or file object.
>
> My question is why I need to do this ObReferenceObject
> and ObDereferenceObject once I got the DeviceObject by
> IoGetDeviceObjectPointer. MUST I do this?
>
> Thanks
>
> Michael
>
>
>
> ______________________________________________________________________
> Post your free ad now! http://personals.yahoo.ca
>
>
“David J. Craig” wrote:
If the PnP manager decides to do its thing, you need some way to keep your
driver and the driver you called in memory until the IRP is completed. You
can use either B or A, but not both. The reference when you got the device
object pointer will be released when your unload routine is called, so you
don’t want the reference count to go to zero before the IRP completes.
Just to amplify a bit, I was thinking that there might be a call to
ObDereferenceObject in some other part of the driver that could be
reached asynchronously, before IoCallDriver returns. For example, you
might have a completion routine for the IRP that releases the reference
matching IoGetDeviceObjectPointer. That completion routine might return
back through the target device’s driver, so you need to make sure that
driver stays in memory.
–
Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Check out our schedule at http://www.oneysoft.com