http://bbs3.driverdevelop.com/simple/?t84347.html
{
BOOL status = ;
DWORD accessMode = , shareMode = ;
HANDLE fileHandle = NULL;
//PUCHAR dataBuffer = NULL;
SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;
UCHAR buffer[ ];
UCHAR string[ ];
ULONG length = , errorCode = ;
DWORD returned = ; 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, ,
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 = ;
sptwb.spt.TargetId = ;
sptwb.spt.Lun = ;
sptwb.spt.CdbLength = CDB6GENERIC_LENGTH;
sptwb.spt.SenseInfoLength = ;
sptwb.spt.DataIn = SCSI_IOCTL_DATA_IN;
sptwb.spt.DataTransferLength = ;
sptwb.spt.TimeOutValue = ;
sptwb.spt.DataBufferOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucDataBuf);
sptwb.spt.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucSenseBuf);
sptwb.spt.Cdb[] = SCSI_OPCODE_HWTEST_COMMAND; //SCSI_OPCODE_SIGMATEL_WRITE_COMMAND;//
sptwb.spt.Cdb[] = HWTEST_DISPLAY_ID;//ALLOCATE_MEDIA;
sptwb.spt.Cdb[] = ;
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;
}