阅读:2566回复:3
写驱动时,想得到hid设备的属性时却得不到?是IOCTL_HID_GET_COLLECTION_INFORMATION用的不得当么?
代码如下:
HID_COLLECTION_INFORMATION HidCi; IO_STATUS_BLOCK IoStatus; KEVENT event; // Initialise IRP completion event KeInitializeEvent(&event, NotificationEvent, FALSE); // Build Internal IOCTL IRP PIRP Irp = IoBuildDeviceIoControlRequest( IOCTL_HID_GET_COLLECTION_INFORMATION, HidDevice, NULL, 0, // Input buffer &HidCi, sizeof(HidCi), // Output buffer TRUE, &event, &IoStatus); DebugPrint(\"HID attributes: VendorID=%4x, ProductID=%4x, VersionNumber=%4x\", HidCi.VendorID, HidCi.ProductID, HidCi.VersionNumber); // Call the driver and wait for completion if necessary NTSTATUS status = IoCallDriver( HidDevice, Irp); 其中HidDevice是HID设备的句柄。 DebugPrint输出的数据是错误的。为什么? 在驱动中应该怎样做呢? |
|
沙发#
发布于:2004-01-10 14:33
Hover:
能告诉我你的代码里“HidDevice”是怎样得到的?filter driver是怎样安装的?对外是表现为一个虚拟串口吗? |
|
板凳#
发布于:2004-01-14 17:19
To mdh_1207:
能告诉我你的代码里“HidDevice”是怎样得到的?filter driver是怎样安装的?对外是表现为一个虚拟串口吗? HidDevice通过IoGetDeviceObjectPointer得到的。 filter driver inf我也不会,想问人家:( 对外是表现为一个虚拟串口. |
|
地板#
发布于:2008-05-19 10:44
我也有同样的问题,请大家帮我看一下,
我想获取的是IOCTL_HID_GET_HARDWARE_ID, 但不能获取,一下是我的代码? extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { DbgPrint("Entering DriverEntry"); NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT fdo = NULL; PFILE_OBJECT fobj = NULL; UNICODE_STRING name; IO_STATUS_BLOCK ioblock; int uBuffLen = 0; unsigned char buff[1024]; RtlInitUnicodeString(&name, L"\\Device\\00000080"); //设置卸载例程,方便卸载 DriverObject->DriverUnload = DriverUnload; //获取设备指针 status = IoGetDeviceObjectPointer(&name, //FILE_READ_ATTRIBUTES, FILE_ALL_ACCESS, &fobj, &fdo); if(!NT_SUCCESS(status)) { DbgPrint("IoGetDeviceObjectPointer failed! 0x%08X", status); return status; } g_fdo = fdo; KEVENT kevent; KeInitializeEvent(&kevent, NotificationEvent, FALSE); PIRP irp = NULL; irp = IoBuildDeviceIoControlRequest(IOCTL_HID_GET_HARDWARE_ID, fdo, NULL, 0, NULL, 0, TRUE, &kevent, &ioblock); if (NULL == irp) { DbgPrint("IoBuildDeviceIoControlRequest failed!"); ObDereferenceObject(fdo); return STATUS_INSUFFICIENT_RESOURCES; } else { DbgPrint("IoBuildDeviceIoControlRequest Succeed!"); } //获取需要分配的空间长度 PIO_STACK_LOCATION stack; stack = IoGetNextIrpStackLocation(irp); DbgPrint("original outbufferlength is: %08X", stack->Parameters.DeviceIoControl.OutputBufferLength); stack->Parameters.DeviceIoControl.OutputBufferLength = 1024; DbgPrint("after outbufferlength is: %08X", stack->Parameters.DeviceIoControl.OutputBufferLength); PMDL mdl = NULL; mdl = IoAllocateMdl(buff, 1024, FALSE, FALSE, NULL); if (NULL != mdl) { MmBuildMdlForNonPagedPool(mdl); // irp->MdlAddress = mdl; //direct way DbgPrint("IoAllocateMdl succeed!"); } else { DbgPrint("IoAllocateMdl faliled!"); } //stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; //stack->MinorFunction = IOCTL_HID_GET_HARDWARE_ID; DbgPrint("mj code : %08X, mn code : %08X", stack->MajorFunction, stack->MinorFunction); DbgPrint("input len: %08X", stack->Parameters.DeviceIoControl.OutputBufferLength); DbgPrint("mdladdr : %08X", irp->MdlAddress); PMDL ormdladdr = irp->MdlAddress; status = IoCallDriver(fdo, irp); if (status == STATUS_PENDING) { status = KeWaitForSingleObject(&kevent, Executive, KernelMode, FALSE, NULL); status = ioblock.Status; } if (NT_SUCCESS(status)) { DbgPrint("out wait, blocksize, %08X", irp->IoStatus.Information); //DbgPrint("irp->mdladdr:%08X, original mdladdr: %08X", irp->MdlAddress, ormdladdr); } else { DbgPrint("ioblock status == faliled! status:%08X, irp->io.status:%08X", status, irp->IoStatus.Status); ObDereferenceObject(fdo); } return status; } =======请问这样获取可以吗? 多谢 |
|