Sorry, modify some error message !
[quoted text clipped - 19 lines]
public byte[] Cdb = new byte[16];
}
You have to take care that you pass a correctly filled and aligned
structure, the buffers need to be fields in the same marshaled structure
(here SCSI_PASS_THROUGH_WITH_BUFFERS).
Here is how you could declare the structure and the
SCSI_PASS_THROUGH_WITH_BUFFERS class.
[StructLayout(LayoutKind.Sequential)]
struct SCSI_PASS_THROUGH_DIRECT
{
public short Length;
public byte ScsiStatus;
public byte PathId;
public byte TargetId;
public byte Lun;
public byte CdbLength;
public byte SenseInfoLength;
public byte DataIn ;
public int DataTransferLength;
public int TimeOutValue;
public IntPtr DataBufferOffset;
public uint SenseInfoOffset;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 16)]
public byte[] Cdb;
};
[StructLayout(LayoutKind.Sequential)]
class SCSI_PASS_THROUGH_WITH_BUFFERS
{
internal SCSI_PASS_THROUGH_DIRECT sptd = new SCSI_PASS_THROUGH_DIRECT();
// // adapt size to suit your needs!!!!!!
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 18)]
internal byte[] sense ;
// adapt to suit your needs!!!!!!!
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 36)]
internal byte[] data ;
};
// usage ...
SCSI_PASS_THROUGH_WITH_BUFFERS info = new
SCSI_PASS_THROUGH_WITH_BUFFERS();
info.sptd.Cdb = new byte[16];
info.sense = new byte[18]; // adapt to suit your needs!!!!!!
info.data = new byte[36]; // adapt to suit your needs!!!!!!
info.sptd.Length = (short)Marshal.SizeOf(info.sptd);
info.sptd.SenseInfoOffset =
(uint)Marshal.OffsetOf(typeof(SCSI_PASS_THROUGH_WITH_BUFFERS), "sense");
info.sptd.SenseInfoLength = (byte)info.sense.Length;
info.sptd.DataTransferLength = info.data.Length;
info.sptd.DataBufferOffset =
Marshal.OffsetOf(typeof(SCSI_PASS_THROUGH_WITH_BUFFERS), "data");
info.sptd.TimeOutValue = 30;
info.sptd.DataIn = SCSI_IOCTL_DATA_IN;
// initilalize the cdb
info.sptd.CdbLength = x; // length of CDB
info.sptd.Cdb[0] = ...;
....
IntPtr inpBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(info));
Marshal.StructureToPtr(info, inpBuffer, false);
// call DeviceIoControl passing the buffer inpBuffer as inp buffer
and/or output buffer depending on the command.
int ret = DeviceIoControl(...., inpBuffer, Marshal.SizeOf(info), ...);
...
Willy.