Getting driver context info when in IOCTL handler?

More newbie questions! Ok, I added instance context data to my driver, and I can set it just fine in my EvtDeviceAdd and EvtDevicePrepareHardware… BUT… how on Earth do I access instance data from the IOCTL, since I don’t have a driver handle??!

I’m sure it’s something simple and my Google-Fu is weak today.

…ed…

xxxxx@woolyloach.com wrote:

More newbie questions! Ok, I added instance context data to my driver, and I can set it just fine in my EvtDeviceAdd and EvtDevicePrepareHardware… BUT… how on Earth do I access instance data from the IOCTL, since I don’t have a driver handle??!

Your context data is not part of the driver object, it’s part of the
device object.

I’m sure it’s something simple and my Google-Fu is weak today.

Must be, since every single KMDF sample does this. One of the cool
things about KMDF is that there is a complete set of “get this from
that” operations. Given a WDFQUEUE, you can get the WDFDEVICE. From
there, you can get the device context:

VOID
MyEvtIoDeviceControl(
IN WDFQUEUE Queue, …
)
{

WDFDEVICE hDevice = WdfIoQueueGetDevice(Queue);
PMY_CONTEXT pContext = MyDeviceGetContext(hDevice);


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

You should have very little context information hanging off of a WDFDRIVER. You want most of your information hanging off of a context of a WDFDEVICE. To get to that context, you need can call WdfIoQueueGetDevice to get the WDFDEVICE in your io event handler.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@woolyloach.com
Sent: Wednesday, October 13, 2010 10:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting driver context info when in IOCTL handler?

More newbie questions! Ok, I added instance context data to my driver, and I can set it just fine in my EvtDeviceAdd and EvtDevicePrepareHardware… BUT… how on Earth do I access instance data from the IOCTL, since I don’t have a driver handle??!

I’m sure it’s something simple and my Google-Fu is weak today.

…ed…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

@Tim - yes, it’s the device, I mis-typed. I guess I shouldn’t come to work with the flu… :-/

@doron - yep, absolutely.

Ok, off to implement this, then I’m going home before I look like even more of an idiot! Thanks for the info!

…ed…

But as someone who often does have a need for global context in a driver [for various test tools needing global control structures, etc.], I’ll just point out that there is WdfGetDriver(), thereby covering even that base :slight_smile:

-----Original Message-----
Sent: Wednesday, October 13, 2010 10:42 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Getting driver context info when in IOCTL handler?

You should have very little context information hanging off of a WDFDRIVER. You want most of your information hanging off of a context of a WDFDEVICE. To get to that context, you need can call WdfIoQueueGetDevice to get the WDFDEVICE in your io event handler.

d

-----Original Message-----
Sent: Wednesday, October 13, 2010 10:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting driver context info when in IOCTL handler?

More newbie questions! Ok, I added instance context data to my driver, and I can set it just fine in my EvtDeviceAdd and EvtDevicePrepareHardware… BUT… how on Earth do I access instance data from the IOCTL, since I don’t have a driver handle??!

I’m sure it’s something simple and my Google-Fu is weak today.

…ed…