阅读:1371回复:3
usb驱动高手请进!
各位大虾:你们好!!!!
我的usb驱动为何AddDevice时创建设备IoCreateDevice总是失败。用softice 也看不到返回值。帮帮我把!!! :( :( |
|
沙发#
发布于:2004-08-26 11:35
把代码贴出来,才知道呀
|
|
板凳#
发布于:2004-08-26 14:51
请看我的代码
NTSTATUS PnpAddDevice( IN PDRIVER_OBJECT pDriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject ) { NTSTATUS ntStatus = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; PDEVICE_EXTENSION pDevExt; //ULONG i; static int ulDeviceNumber = 0; CUString devName("\\Device\\Usb9602"); devName += CUString(ulDeviceNumber); ntStatus = IoCreateDevice( pDriverObject, sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)devName, FILE_DEVICE_UNKNOWN, 0, TRUE, &deviceObject); if (!NT_SUCCESS(ntStatus)) return ntStatus; //程序跳出 // Choose to use BUFFERED_IO deviceObject->Flags |= DO_DIRECT_IO; // Initialize the Device Extension pDevExt = (PDEVICE_EXTENSION)deviceObject->DeviceExtension; pDevExt->pDevice = deviceObject; // back pointer pDevExt->DeviceNumber = ulDeviceNumber; pDevExt->ustrDeviceName = devName; pDevExt->PhysicalDeviceObject=PhysicalDeviceObject; pDevExt->TopOfStackDeviceObject = IoAttachDeviceToDeviceStack(deviceObject,PhysicalDeviceObject); //pDevExt->Irq = Irq; // Form the symbolic link name CUString symLinkName("\\??\\usb9602n"); symLinkName += CUString(ulDeviceNumber+1); // 1 based pDevExt->ustrSymLinkName = symLinkName; // Now create the link name ntStatus = IoCreateSymbolicLink( &(UNICODE_STRING)symLinkName, &(UNICODE_STRING)devName ); if (!NT_SUCCESS(ntStatus)) { // if it fails now, must delete Device object IoDeleteDevice( deviceObject ); return ntStatus; } deviceObject->Flags &= ~DO_DEVICE_INITIALIZING; return ntStatus; } |
|
地板#
发布于:2004-08-26 17:56
ntStatus = IoCreateDevice( pDriverObject,
sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)devName, FILE_DEVICE_UNKNOWN, 0, FALSE, //这里是保留给系统的,驱动应该设置成FALSE &deviceObject); if (!NT_SUCCESS(ntStatus)) |
|