Thanks for the prompt reply. Ya i have already open the file. Please look at the code below. what i want to do is to copy the certain sector of disk as given by user. The problem is sometimes the new image file created shows zero byte and sometime it shows bigger size that the sector given.
hDevice = CreateFile("\\.\" & Oldfilename, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0, 0)
If hDevice = INVALID_HANDLE_VALUE Then Exit Sub
pos = Int(txtstartsector.Text) * 512 'starting sector
endpos = Int(txtendsector.Text) * 512 ' sector up to where to copy
Call SetFilePointer(hDevice, pos, 0, FILE_BEGIN)
Dim file As New filesystemobject
Dim clone_file As TextStream
hclone = CreateFile(FileName, GENERIC_READ Or GENERIC_WRITE, 0, nil, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0)
ReDim TxtBytes(1 To endpos - Int(endpos / 2)) As Byte
For i = LBound(TxtBytes) To UBound(TxtBytes) 'From 0 To The Len Of the File
'OpenTextFile = OpenTextFile & Chr(TxtBytes(I))
nReadRetVal = ReadFile(hDevice, TxtBytes(1), UBound(TxtBytes), Ret, lOverLapped)
nwriteRetVal = WriteFile(hclone, TxtBytes(1), UBound(TxtBytes), Ret, lOverLapped)
i = i + 512
Next
CloseHandle hDevice
CloseHandle hclone
|