akalb
2008-03-20 09:54:57 UTC
how can I write a file over a tape backup
I use the procedure below to get the handle of the tape device, but I
don't know how can I write a file over the tape media. Is there anyone
can help me, please ???
I have found the "write" procedure below but I don' know how can I use
it.
Best regards,
Kalbert
//------------------------------------------------------------------------------
// open the tape drive e get the Handle
//------------------------------------------------------------------------------
function TForm1.OpenDrive:THandle;
var
TapeHandle : THandle;
Security : TSecurityAttributes;
begin
Security.nLength := SizeOf(TSecurityAttributes);
Security.bInheritHandle := FALSE;
Security.lpSecurityDescriptor := nil;
TapeHandle := CreateFile(PChar('\\.\TAPE0'),
GENERIC_READ OR GENERIC_WRITE,
FILE_SHARE_READ OR FILE_SHARE_WRITE,
@SECURITY,
OPEN_EXISTING,
0,
0);
if TapeHandle=INVALID_HANDLE_VALUE then
result := 0
else
result := TapeHandle;
end;
procedure TForm1.Write(iBuffer:Pointer; iBufLen:DWORD);
var
TapeHandle : THandle;
lBytesWritten : DWord;
begin
TapeHandle := OpenDrive;
if not WriteFile(TapeHandle,iBuffer^,iBufLen,lBytesWritten,nil) then
if lBytesWritten <> iBufLen then
ShowMessage('WriteFile only wrote '+IntToStr(lBytesWritten)+'
bytes when'+IntToStr(iBufLen)+' bytes were requested')
else
raise Exception.Create('WriteFile returned an error, code
was'+IntToStr(GetLastError()));
end;
I use the procedure below to get the handle of the tape device, but I
don't know how can I write a file over the tape media. Is there anyone
can help me, please ???
I have found the "write" procedure below but I don' know how can I use
it.
Best regards,
Kalbert
//------------------------------------------------------------------------------
// open the tape drive e get the Handle
//------------------------------------------------------------------------------
function TForm1.OpenDrive:THandle;
var
TapeHandle : THandle;
Security : TSecurityAttributes;
begin
Security.nLength := SizeOf(TSecurityAttributes);
Security.bInheritHandle := FALSE;
Security.lpSecurityDescriptor := nil;
TapeHandle := CreateFile(PChar('\\.\TAPE0'),
GENERIC_READ OR GENERIC_WRITE,
FILE_SHARE_READ OR FILE_SHARE_WRITE,
@SECURITY,
OPEN_EXISTING,
0,
0);
if TapeHandle=INVALID_HANDLE_VALUE then
result := 0
else
result := TapeHandle;
end;
procedure TForm1.Write(iBuffer:Pointer; iBufLen:DWORD);
var
TapeHandle : THandle;
lBytesWritten : DWord;
begin
TapeHandle := OpenDrive;
if not WriteFile(TapeHandle,iBuffer^,iBufLen,lBytesWritten,nil) then
if lBytesWritten <> iBufLen then
ShowMessage('WriteFile only wrote '+IntToStr(lBytesWritten)+'
bytes when'+IntToStr(iBufLen)+' bytes were requested')
else
raise Exception.Create('WriteFile returned an error, code
was'+IntToStr(GetLastError()));
end;