Mega Search
23.2 Million


Sign Up

Make a donation  
DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi XE2  
News Group: embarcadero.public.delphi.nativeapi

I have a code wich works fine when compiled with old versions of Delhi. Hovewer when compiled with Delphi XE2 I get during runtime an error 87 - Incorrect parameter. I suspect that the problem is in the SCSI_PASS_THROUGH_DIRECT structure. The format I am using is

SCSI_PASS_THROUGH_DIRECT = record
    Length: WORD;
    ScsiStatus,
    PathId, TargetId, Lun,
    CdbLength, SenseInfoLength,
    DataIn: Byte;
    DataTransferLength,
    TimeOutValue: Cardinal;
    DataBuffer: PAnsiChar;
    SenseInfoOffset: Cardinal;
    Cdb: array[0..15] of byte;
  end;

However in ntddscsi.h I found another format for 64-bit system

typedef struct _SCSI_PASS_THROUGH_DIRECT {
    USHORT Length;
    UCHAR ScsiStatus;
    UCHAR PathId;
    UCHAR TargetId;
    UCHAR Lun;
    UCHAR CdbLength;
    UCHAR SenseInfoLength;
    UCHAR DataIn;
    ULONG DataTransferLength;
    ULONG TimeOutValue;
    PVOID DataBuffer;
    ULONG SenseInfoOffset;
    UCHAR Cdb[16];
}SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;


//
// Define the SCSI pass through direct structure for Win64 (thunking).
//
#if defined(_WIN64)
typedef struct _SCSI_PASS_THROUGH_DIRECT32 {
    USHORT Length;
    UCHAR ScsiStatus;
    UCHAR PathId;
    UCHAR TargetId;
    UCHAR Lun;
    UCHAR CdbLength;
    UCHAR SenseInfoLength;
    UCHAR DataIn;
    ULONG DataTransferLength;
    ULONG TimeOutValue;
    VOID * POINTER_32 DataBuffer;
    ULONG SenseInfoOffset;
    UCHAR Cdb[16];
}SCSI_PASS_THROUGH_DIRECT32, *PSCSI_PASS_THROUGH_DIRECT32;

#endif

Is any analog of VOID * POINTER_32 for delphi and what else may cause the error 87 in my situation?

Edited by: Search Answer on Nov 1, 2012 6:39 AM

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 1-Nov-2012, at 9:40 AM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
I have changed the SCSI_PASS_THROUGH_DIRECT to 64-bit format and used Integer insted of VOID * POINTER_32 as shown below. DeviceIoControl with IOCTL_SCSI_PASS_THROUGH_DIRECT control code still fails with error 87 if compiled by Delphi XE2. What may be the reason of this error as the same code works fine if compiled by Delphi 2010?

SCSI_PASS_THROUGH_DIRECT = record
    Length: WORD;
    ScsiStatus,
    PathId, TargetId, Lun,
    CdbLength, SenseInfoLength,
    DataIn: Byte;
    DataTransferLength,
    TimeOutValue: Cardinal;
    DataBuffer: Integer;
    SenseInfoOffset: Cardinal;
    Cdb: array[0..15] of byte;
  end;

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Nov-2012, at 2:11 PM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
I tried the structure you offered with {$A8} but the error is the same.

> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> You might also consider changing your declaration to use actual Win32 API 
> data types instead of Delphi data types to ensure the member sizes match. 
How this should be done? Should I include ntddscsi.h c++ header to delphi code?

May I send my entire code to your email, maybe you can find a solution?

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Nov-2012, at 8:59 AM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Do you have the same problem if you configure your project to compile for 
> 32-bit instead of 64-bit?

This is C++ VCL component with code written on Delphi (consists of .pas files). This component is used in C++ Biulder application.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Nov-2012, at 7:07 AM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> C++Builder does 
> not support 64-bit yet, so you have to compile the component for 32-bit and 
> use the 32-bit I/O structures.

That was done first of all because the project was updated from Embarcadero RAD Studio 2010 with 32 bit structures. I tried to use 64 bit structures only after I was unsuccessful with 32 bit structures because I have not any thoughts what else may cause the error 87, cause the project works fine when compiled with Embarcadero RAD Studio 2010.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-Nov-2012, at 6:02 AM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Did you verify that the 32-bit structures are the exact same byte size in 
> both versions?

Sizeof() gives 44 for spt (SCSI_PASS_THROUGH_DIRECT) structure and 80 for SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER in both versions of Rad Studio (2010 and XE2). DeviceIoControl input and output buffers use pointer to variable defined as SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER.

  SCSI_PASS_THROUGH_DIRECT = record
    Length: WORD;
    ScsiStatus,
    PathId, TargetId, Lun,
    CdbLength, SenseInfoLength,
    DataIn: Byte;
    DataTransferLength,
    TimeOutValue: Cardinal;
    DataBuffer: PAnsiChar;
    SenseInfoOffset: Cardinal;
    Cdb: array[0..15] of byte;
  end;

  PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = ^SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = record
    spt: SCSI_PASS_THROUGH_DIRECT;
    Filler: Cardinal;
    ucSenseBuf: array[0..31] of byte;
  end;

Edited by: Search Answer on Nov 14, 2012 6:41 AM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 14-Nov-2012, at 10:42 AM EST
From: Search Answer
 
Re: DeviceIoControl with SCSI_PASS_THROUGH_DIRECT on Delphi  
News Group: embarcadero.public.delphi.nativeapi
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Delphi does not have any concept of a 32-bit Pointer on a 64-bit system. 
>  You will have to use a 32-bit Integer instead, and then type-cast it when 
> needed.

Thank you for your answer. Can you advise how to properly cast Pointer and PAnsiChar to Integer?

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Nov-2012, at 8:51 AM EST
From: Search Answer