有3种常用方式:METHOD_BUFFERED METHOD_IN_DIRECT METHOD_OUT_DIRECT
#define IOSample_IOCTL_BUFFERED CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOSample_IOCTL_IN_DIRECT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define IOSample_IOCTL_OUT_DIRECT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
if (InputBufferLength == 0 || OutputBufferLength == 0)
{ //检查输入、输出参数有效性
WdfRequestComplete(Request, STATUS_INVALID_PARAMETER);
}
else
{
//METHOD_BUFFERED,METHOD_OUT_DIRECT,METHOD_IN_DIRECT三种方式,
//输入缓冲区地址可通过调用WdfRequestRetrieveInputBuffer函数获得
//输出缓冲区地址可通过调用WdfRequestRetrieveOutputBuffer函数获得
//获取输入缓冲区地址buffer
status = WdfRequestRetrieveInputBuffer(Request, 1, &buffer, NULL);
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
}
//buffer表示输入缓冲区地址
//输入x1=应用程序传给驱动程序的数字
x1 = *(UCHAR *)buffer;
//获取输出缓冲区地址buffer
status = WdfRequestRetrieveOutputBuffer(Request, 1, &buffer, NULL);
if (!NT_SUCCESS(status))
{
WdfRequestComplete(Request, STATUS_UNSUCCESSFUL);
break;
}
//输入x2=应用程序通过输出缓冲区传给驱动程序的数字
x2 = *(UCHAR *)buffer;
*(UCHAR *)buffer=x1+x2;
//完成I/O请求,驱动程序传给应用程序的数据长度为1字节
WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, 1);
}
WdfRequestCompleteWithInformation(Request, status, 0);
分析:对于METHOD_BUFFERED:
对于METHOD_OUT_DIRECT,METHOD_IN_DIRECT:
版权声明:本文为博主原创文章,未经博主允许不得转载。