BOOL status = 0; DWORD accessMode = 0, shareMode = 0; HANDLE fileHandle = NULL; //PUCHAR dataBuffer = NULL; SCSI_PASS_THROUGH_WITH_BUFFERS sptwb; SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb; UCHAR buffer[ 2048 ]; UCHAR string[ 25 ]; ULONG length = 0, errorCode = 0; DWORD returned = 0; strcpy(string, "\\\\.\\"); strcat(string, "I:"); shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;//default accessMode = GENERIC_WRITE | GENERIC_READ;//default fileHandle = CreateFile( string, accessMode, shareMode, NULL, OPEN_EXISTING, 0, NULL ); if (fileHandle == INVALID_HANDLE_VALUE) { MessageBox(NULL, "Create file fail", "tester", MB_OK); return false; } ZeroMemory(&sptwb, sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS)); sptwb.spt.Length = sizeof(SCSI_PASS_THROUGH); sptwb.spt.PathId = 0; sptwb.spt.TargetId = 1; sptwb.spt.Lun = 0; sptwb.spt.CdbLength = CDB6GENERIC_LENGTH; sptwb.spt.SenseInfoLength = 24; sptwb.spt.DataIn = SCSI_IOCTL_DATA_IN; sptwb.spt.DataTransferLength = 192; sptwb.spt.TimeOutValue = 2; sptwb.spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucDataBuf); sptwb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucSenseBuf); sptwb.spt.Cdb[0] = SCSI_OPCODE_HWTEST_COMMAND; //SCSI_OPCODE_SIGMATEL_WRITE_COMMAND;// sptwb.spt.Cdb[1] = HWTEST_DISPLAY_ID;//ALLOCATE_MEDIA; sptwb.spt.Cdb[4] = 192; length = offsetof( SCSI_PASS_THROUGH_WITH_BUFFERS, ucDataBuf ) + sptwb.spt.DataTransferLength; status = DeviceIoControl( fileHandle, IOCTL_SCSI_PASS_THROUGH, &sptwb, sizeof(SCSI_PASS_THROUGH), &sptwb, length, &returned, FALSE ); if (!status) { MessageBox(NULL, "Device I/0 control fail!", "tester", MB_OK); errorCode = GetLastError(); ShowMessage(IntToStr(errorCode)); PrintError(errorCode); CloseHandle(fileHandle); return false; } CloseHandle( fileHandle ); return true;
时间: 2023-05-17 19:05:26 浏览: 155
C#值类型、引用类型中的Equals和==的区别浅析
这段代码是用来打开一个名为"I:"的设备文件,并创建一个文件句柄。其中,accessMode表示文件的访问模式,shareMode表示文件的共享模式,fileHandle表示文件句柄。此外,还定义了一些变量和数组用于后续的操作。
阅读全文