Handle value in driver context

Hi all,

How could I get handle value that user mode application gets from
CreateFile when it opens that handle to my driver? That is:

hDevice = CreateFile ( “\\.\MyDevice0”, … );

DeviceIoControl ( hDevice, MYDEVICE_IOCTL_1, … );

There’s MyDevice’s DeviceIoControl dispatches the control request here
and I’d like to know the value of hDevice that has been used in the
DeviceIoControl call.

Is it possible?


Best regards,
D.

You could pass the value within the buffer for a particular ( private ) IOCTL code, just as you do with passing other data
from you user-api to the driver ( and back ). But what do you want to do with that handle value within your driver ?
It is ring 3 user mode specific data that cannot be used within a driver as that.

----- Original Message -----
From: “D. Lex”
To: “NT Developers Interest List”
Sent: Monday, April 21, 2003 2:53 PM
Subject: [ntdev] Handle value in driver context

> Hi all,
>
> How could I get handle value that user mode application gets from
> CreateFile when it opens that handle to my driver? That is:
>
> hDevice = CreateFile ( “\\.\MyDevice0”, … );
> …
> DeviceIoControl ( hDevice, MYDEVICE_IOCTL_1, … );
>
> There’s MyDevice’s DeviceIoControl dispatches the control request here
> and I’d like to know the value of hDevice that has been used in the
> DeviceIoControl call.
>
> Is it possible?
>
> –
> Best regards,
> D.
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

You have access to the FileObject in the Irp. The application handle is an
opaque reference to the FileObject, and that ought to be sufficient.
Otherwise the answer is no, you do not have access to the handle.

-----Original Message-----
From: D. Lex [mailto:xxxxx@netman.ru]
Sent: Monday, April 21, 2003 8:53 AM
To: NT Developers Interest List
Subject: [ntdev] Handle value in driver context

Hi all,

How could I get handle value that user mode application gets
from CreateFile when it opens that handle to my driver? That is:

hDevice = CreateFile ( “\\.\MyDevice0”, … );

DeviceIoControl ( hDevice, MYDEVICE_IOCTL_1, … );

There’s MyDevice’s DeviceIoControl dispatches the control
request here and I’d like to know the value of hDevice that
has been used in the DeviceIoControl call.

Is it possible?


Best regards,
D.


You are currently subscribed to ntdev as:
xxxxx@stratus.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

> There’s MyDevice’s DeviceIoControl dispatches the control request
here

and I’d like to know the value of hDevice that has been used in the
DeviceIoControl call.

No, it is impossible.
If your driver requires different behavior for different file
objects - then allocate some structure in CREATE path and set
FileObject->FsContext2 to it. Do not forget to delete it in CLOSE
path.

Max

Hello Maxim,
Monday, April 21, 2003, 10:22:57 PM, you wrote:

> There’s MyDevice’s DeviceIoControl dispatches the control request here
> and I’d like to know the value of hDevice that has been used in the
> DeviceIoControl call.

MSS> No, it is impossible.
MSS> If your driver requires different behavior for different file
MSS> objects - then allocate some structure in CREATE path and set
MSS> FileObject->FsContext2 to it. Do not forget to delete it in CLOSE
MSS> path.

Thank you much, that’s exactly what I needed. There’s a complete
how-to on this topic in the archive at
http://www.ntdev.org/archive/ntdev0003/msg0229.html.

Oh yes, NTDEV’s archive is a great stuff!


Best regards,
D.