如何将下面这个pas改成DLL编译出来(100分)

  • 主题发起人 主题发起人 swlove
  • 开始时间 开始时间
S

swlove

Unregistered / Unconfirmed
GUEST, unregistred user!
把下面代码保存成SkyHard.pas<br>unit SkyHard;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes;<br><br>const<br>&nbsp; METHOD_BUFFERED = 0;<br><br>&nbsp; FILE_DEVICE_BEEP = $00000001;<br>&nbsp; FILE_DEVICE_CD_ROM = $00000002;<br>&nbsp; FILE_DEVICE_CD_ROM_FILE_SYSTEM = $00000003;<br>&nbsp; FILE_DEVICE_CONTROLLER = $00000004;<br>&nbsp; FILE_DEVICE_DATALINK = $00000005;<br>&nbsp; FILE_DEVICE_DFS = $00000006;<br>&nbsp; FILE_DEVICE_DISK = $00000007;<br>&nbsp; FILE_DEVICE_DISK_FILE_SYSTEM = $00000008;<br>&nbsp; FILE_DEVICE_FILE_SYSTEM = $00000009;<br>&nbsp; FILE_DEVICE_INPORT_PORT = $0000000A;<br>&nbsp; FILE_DEVICE_KEYBOARD = $0000000B;<br>&nbsp; FILE_DEVICE_MAILSLOT = $0000000C;<br>&nbsp; FILE_DEVICE_MIDI_IN = $0000000D;<br>&nbsp; FILE_DEVICE_MIDI_OUT = $0000000E;<br>&nbsp; FILE_DEVICE_MOUSE = $0000000F;<br>&nbsp; FILE_DEVICE_MULTI_UNC_PROVIDER = $00000010;<br>&nbsp; FILE_DEVICE_NAMED_PIPE = $00000011;<br>&nbsp; FILE_DEVICE_NETWORK = $00000012;<br>&nbsp; FILE_DEVICE_NETWORK_BROWSER = $00000013;<br>&nbsp; FILE_DEVICE_NETWORK_FILE_SYSTEM = $00000014;<br>&nbsp; FILE_DEVICE_NULL = $00000015;<br>&nbsp; FILE_DEVICE_PARALLEL_PORT = $00000016;<br>&nbsp; FILE_DEVICE_PHYSICAL_NETCARD = $00000017;<br>&nbsp; FILE_DEVICE_PRINTER = $00000018;<br>&nbsp; FILE_DEVICE_SCANNER = $00000019;<br>&nbsp; FILE_DEVICE_SERIAL_MOUSE_PORT = $0000001A;<br>&nbsp; FILE_DEVICE_SERIAL_PORT = $0000001B;<br>&nbsp; FILE_DEVICE_SCREEN = $0000001C;<br>&nbsp; FILE_DEVICE_SOUND = $0000001D;<br>&nbsp; FILE_DEVICE_STREAMS = $0000001E;<br>&nbsp; FILE_DEVICE_TAPE = $0000001F;<br>&nbsp; FILE_DEVICE_TAPE_FILE_SYSTEM = $00000020;<br>&nbsp; FILE_DEVICE_TRANSPORT = $00000021;<br>&nbsp; FILE_DEVICE_UNKNOWN = $00000022;<br>&nbsp; FILE_DEVICE_VIDEO = $00000023;<br>&nbsp; FILE_DEVICE_VIRTUAL_DISK = $00000024;<br>&nbsp; FILE_DEVICE_WAVE_IN = $00000025;<br>&nbsp; FILE_DEVICE_WAVE_OUT = $00000026;<br>&nbsp; FILE_DEVICE_8042_PORT = $00000027;<br>&nbsp; FILE_DEVICE_NETWORK_REDIRECTOR = $00000028;<br>&nbsp; FILE_DEVICE_BATTERY = $00000029;<br>&nbsp; FILE_DEVICE_BUS_EXTENDER = $0000002A;<br>&nbsp; FILE_DEVICE_MODEM = $0000002B;<br>&nbsp; FILE_DEVICE_VDM = $0000002C;<br>&nbsp; FILE_DEVICE_MASS_STORAGE = $0000002D;<br>&nbsp; FILE_DEVICE_SMB = $0000002E;<br>&nbsp; FILE_DEVICE_KS = $0000002F;<br>&nbsp; FILE_DEVICE_CHANGER = $00000030;<br>&nbsp; FILE_DEVICE_SMARTCARD = $00000031;<br>&nbsp; FILE_DEVICE_ACPI = $00000032;<br>&nbsp; FILE_DEVICE_DVD = $00000033;<br>&nbsp; FILE_DEVICE_FULLSCREEN_VIDEO = $00000034;<br>&nbsp; FILE_DEVICE_DFS_FILE_SYSTEM = $00000035;<br>&nbsp; FILE_DEVICE_DFS_VOLUME = $00000036;<br>&nbsp; FILE_DEVICE_SERENUM = $00000037;<br>&nbsp; FILE_DEVICE_TERMSRV = $00000038;<br>&nbsp; FILE_DEVICE_KSEC = $00000039;<br>&nbsp; FILE_DEVICE_FIPS = $0000003A;<br>&nbsp; FILE_DEVICE_INFINIBAND = $0000003B;<br><br>&nbsp; FILE_ANY_ACCESS = 0;<br>&nbsp; FILE_SPECIAL_ACCESS = FILE_ANY_ACCESS;<br>&nbsp; FILE_READ_ACCESS = $0001; // file &amp; pipe<br>&nbsp; FILE_WRITE_ACCESS = $0002; // file &amp; pipe<br><br>&nbsp; SCSI_IOCTL_DATA_OUT = 0;<br>&nbsp; SCSI_IOCTL_DATA_IN = 1;<br>&nbsp; SCSI_IOCTL_DATA_UNSPECIFIED = 2;<br><br>&nbsp; CDB_INQUIRY_EVPD = 1;<br><br>&nbsp; SCSIOP_INQUIRY = $12;<br>&nbsp; SCSIOP_MODE_SENSE = $1A;<br><br>&nbsp; MODE_PAGE_CAPABILITIES = $2A;<br><br>&nbsp; CDB6GENERIC_LENGTH = 6;<br><br>&nbsp; IOCTL_SCSI_BASE = FILE_DEVICE_CONTROLLER;<br>&nbsp; IOCTL_STORAGE_BASE = FILE_DEVICE_MASS_STORAGE;<br>&nbsp; IOCTL_SCSI_MINIPORT_IDENTIFY = ((FILE_DEVICE_SERIAL_PORT shl 16) + $0501); //$001b0501<br>&nbsp; IOCTL_SCSI_MINIPORT = ((IOCTL_SCSI_BASE shl 16) or ($0402 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14)); //$0004D008<br>&nbsp; IOCTL_SCSI_PASS_THROUGH = ((IOCTL_SCSI_BASE shl 16) or ($0401 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14));<br>&nbsp; IOCTL_SCSI_GET_INQUIRY_DATA = ((IOCTL_SCSI_BASE shl 16) or ($0403 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_GET_CAPABILITIES = ((IOCTL_SCSI_BASE shl 16) or ($0404 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_PASS_THROUGH_DIRECT = ((IOCTL_SCSI_BASE shl 16) or ($0405 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14));<br>&nbsp; IOCTL_SCSI_GET_ADDRESS = ((IOCTL_SCSI_BASE shl 16) or ($0406 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_RESCAN_BUS = ((IOCTL_SCSI_BASE shl 16) or ($0407 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_GET_DUMP_POINTERS = ((IOCTL_SCSI_BASE shl 16) or ($0408 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br><br>&nbsp; IOCTL_DISK_BASE = FILE_DEVICE_DISK;<br>&nbsp; IOCTL_DISK_GET_DRIVE_GEOMETRY = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0000 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_GET_PARTITION_INFO = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_READ_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0001 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_GET_DRIVE_LAYOUT = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_READ_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0003 shl 2) or METHOD_BUFFERED);<br><br>&nbsp; IOCTL_VOLUME_BASE = Cardinal('V');<br>&nbsp; IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = (<br>&nbsp; &nbsp; (IOCTL_VOLUME_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; (0 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_CONTROLLER_NUMBER = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0011 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_STORAGE_GET_MEDIA_TYPES_EX = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0301 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0304 shl 2) or METHOD_BUFFERED);<br><br>&nbsp; IOCTL_STORAGE_QUERY_PROPERTY = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0500 shl 2) or METHOD_BUFFERED);<br><br>type<br>&nbsp; TDiskExtent = record<br>&nbsp; &nbsp; DiskNumber: Cardinal;<br>&nbsp; &nbsp; StartingOffset: LARGE_INTEGER;<br>&nbsp; &nbsp; ExtentLength: LARGE_INTEGER;<br>&nbsp; end;<br>&nbsp; DISK_EXTENT = TDiskExtent;<br>&nbsp; PDiskExtent = ^TDiskExtent;<br><br>&nbsp; TVolumeDiskExtents = record<br>&nbsp; &nbsp; NumberOfDiskExtents: Cardinal;<br>&nbsp; &nbsp; Extents: array[0..0] of TDiskExtent;<br>&nbsp; end;<br>&nbsp; VOLUME_DISK_EXTENTS = TVolumeDiskExtents;<br>&nbsp; PVolumeDiskExtents = ^TVolumeDiskExtents;<br><br><br>function GetVolumeInfo(DriverLetter: Char): TDiskExtent;<br><br>implementation<br><br>function GetVolumeInfo(DriverLetter: Char): TDiskExtent;<br>var<br>&nbsp; hVolume: THandle;<br>&nbsp; DiskExtents: PVolumeDiskExtents;<br>&nbsp; dwOutBytes: Cardinal;<br>begin<br>&nbsp; with Result do<br>&nbsp; begin<br>&nbsp; &nbsp; DiskNumber := 0;<br>&nbsp; &nbsp; StartingOffset.QuadPart := 0;<br>&nbsp; &nbsp; ExtentLength.QuadPart := 0;<br>&nbsp; end;<br>&nbsp; hVolume := CreateFile(PChar('//./' + DriverLetter + ':'), GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);<br>&nbsp; if hVolume &lt; 1 then Exit;<br>&nbsp; DiskExtents := AllocMem(Max_Path);<br>&nbsp; if DeviceIoControl(hVolume,<br>&nbsp; &nbsp; IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,<br>&nbsp; &nbsp; nil, 0,<br>&nbsp; &nbsp; DiskExtents, Max_Path,<br>&nbsp; &nbsp; dwOutBytes, nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; if DiskExtents^.NumberOfDiskExtents &gt; 0 then<br>&nbsp; &nbsp; &nbsp; Result := DiskExtents^.Extents[0];<br>&nbsp; end;<br>&nbsp; FreeMem(DiskExtents);<br>&nbsp; CloseHandle(hVolume);<br>end;<br><br>end.<br><br>然后在工程里引用就可以得到结果<br>uses SkyHard;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; Memo1.Text:=IntToStr(GetVolumeInfo('C').DiskNumber);<br>end;<br><br>但我想把上面那pas文件编译成DLL以方便其他程序调用,该如何做 ?
 
你只须将这个单元加入Dll的工程里,在Dll的工程里用exports引出GetVolumeInfo函数就行了。
 
正常Dll的写法
 
!dll!<br>library Project1;<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes;<br><br>const<br>&nbsp; METHOD_BUFFERED = 0;<br><br>&nbsp; FILE_DEVICE_BEEP = $00000001;<br>&nbsp; FILE_DEVICE_CD_ROM = $00000002;<br>&nbsp; FILE_DEVICE_CD_ROM_FILE_SYSTEM = $00000003;<br>&nbsp; FILE_DEVICE_CONTROLLER = $00000004;<br>&nbsp; FILE_DEVICE_DATALINK = $00000005;<br>&nbsp; FILE_DEVICE_DFS = $00000006;<br>&nbsp; FILE_DEVICE_DISK = $00000007;<br>&nbsp; FILE_DEVICE_DISK_FILE_SYSTEM = $00000008;<br>&nbsp; FILE_DEVICE_FILE_SYSTEM = $00000009;<br>&nbsp; FILE_DEVICE_INPORT_PORT = $0000000A;<br>&nbsp; FILE_DEVICE_KEYBOARD = $0000000B;<br>&nbsp; FILE_DEVICE_MAILSLOT = $0000000C;<br>&nbsp; FILE_DEVICE_MIDI_IN = $0000000D;<br>&nbsp; FILE_DEVICE_MIDI_OUT = $0000000E;<br>&nbsp; FILE_DEVICE_MOUSE = $0000000F;<br>&nbsp; FILE_DEVICE_MULTI_UNC_PROVIDER = $00000010;<br>&nbsp; FILE_DEVICE_NAMED_PIPE = $00000011;<br>&nbsp; FILE_DEVICE_NETWORK = $00000012;<br>&nbsp; FILE_DEVICE_NETWORK_BROWSER = $00000013;<br>&nbsp; FILE_DEVICE_NETWORK_FILE_SYSTEM = $00000014;<br>&nbsp; FILE_DEVICE_NULL = $00000015;<br>&nbsp; FILE_DEVICE_PARALLEL_PORT = $00000016;<br>&nbsp; FILE_DEVICE_PHYSICAL_NETCARD = $00000017;<br>&nbsp; FILE_DEVICE_PRINTER = $00000018;<br>&nbsp; FILE_DEVICE_SCANNER = $00000019;<br>&nbsp; FILE_DEVICE_SERIAL_MOUSE_PORT = $0000001A;<br>&nbsp; FILE_DEVICE_SERIAL_PORT = $0000001B;<br>&nbsp; FILE_DEVICE_SCREEN = $0000001C;<br>&nbsp; FILE_DEVICE_SOUND = $0000001D;<br>&nbsp; FILE_DEVICE_STREAMS = $0000001E;<br>&nbsp; FILE_DEVICE_TAPE = $0000001F;<br>&nbsp; FILE_DEVICE_TAPE_FILE_SYSTEM = $00000020;<br>&nbsp; FILE_DEVICE_TRANSPORT = $00000021;<br>&nbsp; FILE_DEVICE_UNKNOWN = $00000022;<br>&nbsp; FILE_DEVICE_VIDEO = $00000023;<br>&nbsp; FILE_DEVICE_VIRTUAL_DISK = $00000024;<br>&nbsp; FILE_DEVICE_WAVE_IN = $00000025;<br>&nbsp; FILE_DEVICE_WAVE_OUT = $00000026;<br>&nbsp; FILE_DEVICE_8042_PORT = $00000027;<br>&nbsp; FILE_DEVICE_NETWORK_REDIRECTOR = $00000028;<br>&nbsp; FILE_DEVICE_BATTERY = $00000029;<br>&nbsp; FILE_DEVICE_BUS_EXTENDER = $0000002A;<br>&nbsp; FILE_DEVICE_MODEM = $0000002B;<br>&nbsp; FILE_DEVICE_VDM = $0000002C;<br>&nbsp; FILE_DEVICE_MASS_STORAGE = $0000002D;<br>&nbsp; FILE_DEVICE_SMB = $0000002E;<br>&nbsp; FILE_DEVICE_KS = $0000002F;<br>&nbsp; FILE_DEVICE_CHANGER = $00000030;<br>&nbsp; FILE_DEVICE_SMARTCARD = $00000031;<br>&nbsp; FILE_DEVICE_ACPI = $00000032;<br>&nbsp; FILE_DEVICE_DVD = $00000033;<br>&nbsp; FILE_DEVICE_FULLSCREEN_VIDEO = $00000034;<br>&nbsp; FILE_DEVICE_DFS_FILE_SYSTEM = $00000035;<br>&nbsp; FILE_DEVICE_DFS_VOLUME = $00000036;<br>&nbsp; FILE_DEVICE_SERENUM = $00000037;<br>&nbsp; FILE_DEVICE_TERMSRV = $00000038;<br>&nbsp; FILE_DEVICE_KSEC = $00000039;<br>&nbsp; FILE_DEVICE_FIPS = $0000003A;<br>&nbsp; FILE_DEVICE_INFINIBAND = $0000003B;<br><br>&nbsp; FILE_ANY_ACCESS = 0;<br>&nbsp; FILE_SPECIAL_ACCESS = FILE_ANY_ACCESS;<br>&nbsp; FILE_READ_ACCESS = $0001; // file &amp; pipe<br>&nbsp; FILE_WRITE_ACCESS = $0002; // file &amp; pipe<br><br>&nbsp; SCSI_IOCTL_DATA_OUT = 0;<br>&nbsp; SCSI_IOCTL_DATA_IN = 1;<br>&nbsp; SCSI_IOCTL_DATA_UNSPECIFIED = 2;<br><br>&nbsp; CDB_INQUIRY_EVPD = 1;<br><br>&nbsp; SCSIOP_INQUIRY = $12;<br>&nbsp; SCSIOP_MODE_SENSE = $1A;<br><br>&nbsp; MODE_PAGE_CAPABILITIES = $2A;<br><br>&nbsp; CDB6GENERIC_LENGTH = 6;<br><br>&nbsp; IOCTL_SCSI_BASE = FILE_DEVICE_CONTROLLER;<br>&nbsp; IOCTL_STORAGE_BASE = FILE_DEVICE_MASS_STORAGE;<br>&nbsp; IOCTL_SCSI_MINIPORT_IDENTIFY = ((FILE_DEVICE_SERIAL_PORT shl 16) + $0501); //$001b0501<br>&nbsp; IOCTL_SCSI_MINIPORT = ((IOCTL_SCSI_BASE shl 16) or ($0402 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14)); //$0004D008<br>&nbsp; IOCTL_SCSI_PASS_THROUGH = ((IOCTL_SCSI_BASE shl 16) or ($0401 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14));<br>&nbsp; IOCTL_SCSI_GET_INQUIRY_DATA = ((IOCTL_SCSI_BASE shl 16) or ($0403 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_GET_CAPABILITIES = ((IOCTL_SCSI_BASE shl 16) or ($0404 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_PASS_THROUGH_DIRECT = ((IOCTL_SCSI_BASE shl 16) or ($0405 shl 2) or METHOD_BUFFERED or ((FILE_READ_ACCESS or FILE_WRITE_ACCESS) shl 14));<br>&nbsp; IOCTL_SCSI_GET_ADDRESS = ((IOCTL_SCSI_BASE shl 16) or ($0406 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_RESCAN_BUS = ((IOCTL_SCSI_BASE shl 16) or ($0407 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br>&nbsp; IOCTL_SCSI_GET_DUMP_POINTERS = ((IOCTL_SCSI_BASE shl 16) or ($0408 shl 2) or METHOD_BUFFERED or (FILE_ANY_ACCESS shl 14));<br><br>&nbsp; IOCTL_DISK_BASE = FILE_DEVICE_DISK;<br>&nbsp; IOCTL_DISK_GET_DRIVE_GEOMETRY = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0000 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_GET_PARTITION_INFO = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_READ_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0001 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_GET_DRIVE_LAYOUT = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_READ_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0003 shl 2) or METHOD_BUFFERED);<br><br>&nbsp; IOCTL_VOLUME_BASE = Cardinal('V');<br>&nbsp; IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = (<br>&nbsp; &nbsp; (IOCTL_VOLUME_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; (0 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_DISK_CONTROLLER_NUMBER = (<br>&nbsp; &nbsp; (IOCTL_DISK_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0011 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_STORAGE_GET_MEDIA_TYPES_EX = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0301 shl 2) or METHOD_BUFFERED);<br>&nbsp; IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0304 shl 2) or METHOD_BUFFERED);<br><br>&nbsp; IOCTL_STORAGE_QUERY_PROPERTY = (<br>&nbsp; &nbsp; (IOCTL_STORAGE_BASE shl 16) or (FILE_ANY_ACCESS shl 14) or<br>&nbsp; &nbsp; ($0500 shl 2) or METHOD_BUFFERED);<br><br>type<br>&nbsp; TDiskExtent = record<br>&nbsp; &nbsp; DiskNumber: Cardinal;<br>&nbsp; &nbsp; StartingOffset: LARGE_INTEGER;<br>&nbsp; &nbsp; ExtentLength: LARGE_INTEGER;<br>&nbsp; end;<br>&nbsp; DISK_EXTENT = TDiskExtent;<br>&nbsp; PDiskExtent = ^TDiskExtent;<br><br>&nbsp; TVolumeDiskExtents = record<br>&nbsp; &nbsp; NumberOfDiskExtents: Cardinal;<br>&nbsp; &nbsp; Extents: array[0..0] of TDiskExtent;<br>&nbsp; end;<br>&nbsp; VOLUME_DISK_EXTENTS = TVolumeDiskExtents;<br>&nbsp; PVolumeDiskExtents = ^TVolumeDiskExtents;<br><br>function GetVolumeInfo(DriverLetter: Char): TDiskExtent;<br>var<br>&nbsp; hVolume: THandle;<br>&nbsp; DiskExtents: PVolumeDiskExtents;<br>&nbsp; dwOutBytes: Cardinal;<br>begin<br>&nbsp; with Result do<br>&nbsp; begin<br>&nbsp; &nbsp; DiskNumber := 0;<br>&nbsp; &nbsp; StartingOffset.QuadPart := 0;<br>&nbsp; &nbsp; ExtentLength.QuadPart := 0;<br>&nbsp; end;<br>&nbsp; hVolume := CreateFile(PChar('//./' + DriverLetter + ':'), GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);<br>&nbsp; if hVolume &lt; 1 then Exit;<br>&nbsp; DiskExtents := AllocMem(Max_Path);<br>&nbsp; if DeviceIoControl(hVolume,<br>&nbsp; &nbsp; IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,<br>&nbsp; &nbsp; nil, 0,<br>&nbsp; &nbsp; DiskExtents, Max_Path,<br>&nbsp; &nbsp; dwOutBytes, nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; if DiskExtents^.NumberOfDiskExtents &gt; 0 then<br>&nbsp; &nbsp; &nbsp; Result := DiskExtents^.Extents[0];<br>&nbsp; end;<br>&nbsp; FreeMem(DiskExtents);<br>&nbsp; CloseHandle(hVolume);<br>end;<br>exports<br>GetVolumeInfo;<br>begin<br>end.<br>exe!!!!!!!!!!!!!!!!!!!!!!!!!!!!<br>TDiskExtent = record<br>&nbsp; &nbsp; DiskNumber: Cardinal;<br>&nbsp; &nbsp; StartingOffset: LARGE_INTEGER;<br>&nbsp; &nbsp; ExtentLength: LARGE_INTEGER;<br>&nbsp; end;<br>&nbsp; DISK_EXTENT = TDiskExtent;<br>&nbsp; PDiskExtent = ^TDiskExtent;<br>TVolumeDiskExtents = record<br>&nbsp; &nbsp; NumberOfDiskExtents: Cardinal;<br>&nbsp; &nbsp; Extents: array[0..0] of TDiskExtent;<br>&nbsp; end;<br>&nbsp; VOLUME_DISK_EXTENTS = TVolumeDiskExtents;<br>&nbsp; PVolumeDiskExtents = ^TVolumeDiskExtents;<br>type<br>&nbsp;TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>function GetVolumeInfo(DriverLetter: Char): TDiskExtent;external 'project1.dll';<br><br><br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>GetVolumeInfo('c');<br>end;<br><br>end.
 
搞掂,谢谢
 
后退
顶部