Just look at the example below and please help me.
if WriteFile(hDevice, bfile, 512, size, nil) then ShowMessage('Ok');
As above I use the 512, it worked, but with 440 as below, no.
if WriteFile(hDevice, bfile, 440, size, nil) then ShowMessage('Ok');
My question, how can write a file size of 440 or less than 512 byte?
hDevice := CreateFile('\\.\PHYSICALDRIVE1', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
bfile := CreateFile('C:\Users\Administrator\Downloads\bfile', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if bfile <> INVALID_HANDLE_VALUE then
begin
ShowMessage(IntToStr(getlasterror));
//SetFilePointer(hDevice,0,nil,FILE_BEGIN); // replace 0 with sector that you wish to read
if WriteFile(hDevice, bfile, 440, size, nil) then ShowMessage('b');
ShowMessage(IntToStr(getlasterror));
CloseHandle(hDevice);
end;
end;
GetLastErrorreturn when the function fails? - Tom Brunberg