![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Работа с HDD [D7, 95/98, ME, NT4, 2000, XP, 2003]
Tsa © (2006-02-07 14:04:00)Добрый день подскажите пожалуйста как в Делфи можно работать с жеским диском на нихком уровне, "бегать" по секторам и т.п.
Tsa (2006-02-07 15:53:00) [1]:-) WriteFile запишет такимже образом необходимые денные (байты) по секторам,
Fay (2006-02-07 15:35:00) [2]сдаюсь.
язык, вроде, знакомый, но не понятно ничего.
Tsa (2006-02-07 15:25:00) [3]Да вопрос забыл на брать ?
Fay (2006-02-07 15:23:00) [4]Это вопрос? Можно переписать его в недвусмысленную форму?
Tsa (2006-02-07 15:20:00) [5]WriteFile запишет такимже образом по секторам
Tsa (2006-02-07 15:11:00) [6]Спасибо !
а записать данные каким образом можно ?
Fay (2006-02-07 15:11:00) [7]WriteFile
ZeroDivide (2006-02-07 14:41:00) [8]Собственно для HDD так же, просто это я к тому, чтобы hCDROM не смущал.
ZeroDivide (2006-02-07 14:39:00) [9]Приведенный ниже кусок кода написан для CD-ROM'а и под Windows NT:
var
hCDROM: THandle; // file handle to entire CD-ROM
IoBuffer: Pointer; // page-aligned buffer
const
cd_name = '\\.\r:';
// get a page-aligned buffer, required for direct IO operations
IoBuffer := VirtualAlloc (nil, sector_size, MEM_COMMIT, PAGE_READWRITE);
// connect to the CD-ROM directly, note the file name used....
hCDROM := CreateFile (cd_name, GENERIC_READ, FILE_SHARE_READ, nil,
OPEN_EXISTING, 0, 0);
if hCDROM = INVALID_HANDLE_VALUE then
begin
er := GetLastError;
Raise Exception.Create (
'Failed to connect to CD-ROM drive, error ' + IntToStr (er));
end;
Having connected, reading a sector:
function TForm1.read_sector (sect: integer; var buf: cd_sector): boolean;
var
byte_pos: integer; // restricted to 2GB CDs by 32-bit byte address
bytes_read: integer; // number of bytes read from the CD
OK: Boolean; // result of the read
begin
Result := False; // assume failure
byte_pos := sector_size * sect; // compute byte position on the CD
// try to do a SEEK into the CD, if that works, do the actual read
if SetFilePointer (hCDROM, byte_pos, nil, FILE_BEGIN) = byte_pos then
begin
// read a sector of data into our page-aligned buffer
OK := ReadFile (hCDROM, IoBuffer^, sector_size, bytes_read, nil);
// copy the sector of data to the caller's buffer
if OK then Move (IoBuffer^, buf, SizeOf (cd_sector));
Result := OK; // return the result of the read
end;
end;
Fay (2006-02-07 14:12:00) [10]CreateFile не катит?