"Marce via DotNetMonster.com" <u34601@uwewrote in message
news:72e5d0179de3d@uwe...
Sorry, modify some error message !
[StructLayout(LayoutKind.Sequential)]
class SCSI_PASS_THROUGH_DIRECT
{
public UInt16 Length = (UInt16)Marshal.SizeOf(typeof
(SCSI_PASS_THROUGH_DIRECT));
public byte ScsiStatus = 0;
public byte PathId= 0;
public byte TargetId= 0;
public byte Lun = 0;
public byte CdbLength = 12;
public byte SenseInfoLength = 24;
public byte DataIn ;
public Int32 DataTransferLength;
public Int32 TimeOutValue= 30;
public IntPtr DataBuffer;
public UInt32 SenseInfoOffset = (UInt32)Marshal.OffsetOf(typeof
(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFERS), "ucSenseBuf");
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 16)]
public byte[] Cdb = new byte[16];
}
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200705/1
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_WI TH_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_BUF FERS), "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.