阅读:1330回复:2
API 中 CreateFile 的第一个参数(设备名)对应 驱动程序中的那个字段(或名称)
API 中 CreateFile 的第一个参数(设备名)对应 驱动程序中的那个字段(或名称)
API: hDevice = CreateFile("\\\\.\\LBK1",GENERIC_READ | GENERIC_WRITE, 0, // share mode none NULL, // no security OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); 驱动程序: NTSTATUS CreateDevice ( IN PDRIVER_OBJECT pDriverObject, IN ULONG ulDeviceNumber ) { NTSTATUS status; PDEVICE_OBJECT pDevObj; PDEVICE_EXTENSION pDevExt; // Form the internal Device Name CUString devName("\\Device\\LOOPBACK"); // for "loopback" device devName += CUString(ulDeviceNumber); // Now create the device status = IoCreateDevice( pDriverObject, sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)devName, FILE_DEVICE_UNKNOWN, 0, TRUE, &pDevObj ); if (!NT_SUCCESS(status)) return status; // Announce that we will be working with a copy of the user's buffer pDevObj->Flags |= DO_BUFFERED_IO; // Initialize the Device Extension pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevice = pDevObj; // back pointer pDevExt->DeviceNumber = ulDeviceNumber; pDevExt->ustrDeviceName = devName; pDevExt->deviceBuffer = NULL; pDevExt->deviceBufferSize = 0; // Form the symbolic link name CUString symLinkName("\\??\\LBK");// ??表示什么意思? symLinkName += CUString(ulDeviceNumber+1); +1 表示什么意思? // 1 based pDevExt->ustrSymLinkName = symLinkName; // Now create the link name status = IoCreateSymbolicLink( &(UNICODE_STRING)symLinkName, &(UNICODE_STRING)devName ); if (!NT_SUCCESS(status)) { // if it fails now, must delete Device object IoDeleteDevice( pDevObj ); return status; } // Made it return STATUS_SUCCESS; } |
|
沙发#
发布于:2005-01-25 18:15
CreateFile 的第一个参数(设备名)\\\\\\\\.\\\\LBK1
是从1开始 对应 驱动程序中的符号连接名\\\\??\\\\LBK或\\\\DosDevices\\\\LBK,两种方式是一样的 是从0开始, 所以那里要加上1了 |
|
|
板凳#
发布于:2005-01-25 23:05
CreateFile 的第一个参数(设备名)\\\\.\\LBK1 对 ulDeviceNumber+1是为了处理多个设备重名的情况。 |
|
|