How can I define IOCTL_ATA_PASS_THROUGH in delphi?

I work with the DeviceIoControl function, and I need to pass the IOCTL_ATA_PASS_THROUGH value IOCTL_ATA_PASS_THROUGH this function. I canโ€™t find the Delphi translation for this constant, I just found this definition in C ++.

 # define IOCTL_ATA_PASS_THROUGH CTL_CODE(IOCTL_SCSI_BASE, 0x040B, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) 

but I am having trouble translating this value into delphi using the CTL_CODE macro. the question is, how can I define IOCTL_ATA_PASS_THROUGH in delphi?

+4
source share
2 answers

The CTL_CODE macro is defined as

 #define CTL_CODE(DeviceType, Function, Method, Access) ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) ) 

So the equivalent of delphi IOCTL_ATA_PASS_THROUGH const is something like this

 uses Windows; const //#define IOCTL_ATA_PASS_THROUGH CTL_CODE(IOCTL_SCSI_BASE, 0x040B, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) IOCTL_SCSI_BASE = FILE_DEVICE_CONTROLLER; IOCTL_ATA_PASS_THROUGH= (IOCTL_SCSI_BASE shl 16) or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14) or ($040B shl 2) or (METHOD_BUFFERED); 

Note. Unfortunately, delphi does not support macros, but you can create a function

 function CTL_CODE(DeviceType, _Function, Method, Access: Cardinal): Cardinal; begin Result := (DeviceType shl 16) or (Access Shl 14) or (_Function shl 2) or (Method); end; 

and thus get the value at runtime

 Flag:=CTL_CODE(IOCTL_SCSI_BASE, $040B , METHOD_BUFFERED, (FILE_READ_ACCESS or FILE_WRITE_ACCESS)); 
+9
source

It has a value of $0004d02c . I got this with the following C program.

 #include <windows.h> #include <Ntddscsi.h> #include <stdio.h> int main(int argc, char* argv[]) { printf("%.8x", IOCTL_ATA_PASS_THROUGH); return 0; } 

I personally find it safer to use the actual Windows header files than trying to translate, but maybe that's because I don't know enough about C!

+1
source

Source: https://habr.com/ru/post/1391674/


All Articles