Send information from driver to application using DeviceIoControl

Hello!

I have written a driver and an application, and I want the application to send an IOCTL to the driver, and then the driver to send some info to it. I want finally to send a string, so I try to send a pointer to the variable. (For the simplicity, I send a pointer to an ULONG variable).

I do it this way:

ULONG num;
ULONG *pNum;

num = 55;
Irp->AssociatedIrp.SystemBuffer = pNum;
Irp->IoStatus.Information = sizeof(pNum);
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);

When I send the IOCTL to the driver, I get a blue screen. I tried to send a number instead of a pointer, but that also doesn’t work.

My CTL CODE:

#define FILE_DEVICE_WDJDRV 0x00009500

#define WDJ_IOCTL_INDEX 0x950

#define IOCTL_WDJ_REQUEST CTL_CODE(FILE_DEVICE_WDJDRV, WDJ_IOCTL_INDEX, METHOD_BUFFERED, FILE_ANY_ACCESS)

Can anyone help me with this?

I would be very thankful…

Take a look at the IOCTL sample in src\general\ioctl in the WDK. You
cannot pass a pointer from kernel to user space, you need to copy the
string into the buffer.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntfsd…
> Hello!
>
> I have written a driver and an application, and I want the application to
> send an IOCTL to the driver, and then the driver to send some info to it.
> I want finally to send a string, so I try to send a pointer to the
> variable. (For the simplicity, I send a pointer to an ULONG variable).
>
> I do it this way:
>
> ULONG num;
> ULONG *pNum;
>
> num = 55;
> Irp->AssociatedIrp.SystemBuffer = pNum;
> Irp->IoStatus.Information = sizeof(pNum);
> Irp->IoStatus.Status = STATUS_SUCCESS;
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> When I send the IOCTL to the driver, I get a blue screen. I tried to send
> a number instead of a pointer, but that also doesn’t work.
>
> My CTL CODE:
>
> #define FILE_DEVICE_WDJDRV 0x00009500
>
> #define WDJ_IOCTL_INDEX 0x950
>
> #define IOCTL_WDJ_REQUEST CTL_CODE(FILE_DEVICE_WDJDRV, WDJ_IOCTL_INDEX,
> METHOD_BUFFERED, FILE_ANY_ACCESS)
>
> Can anyone help me with this?
>
> I would be very thankful…
>

Ok, thanks!

I will look at it.

I’m sorry, but I didn’t understand the sample… Can you explain it to me?

Thank you very much!

Take a look at the SioctlDeviceControl routine, it is a 4 way case
statement to show how to do each of the types of buffering of the IOCTL’s.
This is an extremely simple example, if you are not following this, you
should seriously consider finding someone to do the code for you, since
most kernel code has more complexity than this example. Since you are
asking these questions on the file system discussion list this is very
scary, since this is one of the hardest areas in the kernel.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntfsd…
> I’m sorry, but I didn’t understand the sample… Can you explain it to
> me?
>
> Thank you very much!
>

Thanks!