| | | Forum Newbie
       
Group: Forum Members Last Login: 6/10/2009 8:57:40 AM Posts: 7, Visits: 18 |
| Hi! I am doing a program in which user give sector of harddisk, then that sector must be read and write to another file( disk imaging (only some parts)). The problem i am having is that i can read the sector from the specified harddisk but am not able to write or append to new file. The new file i created always shows the 0 byte. Can anybody help me with the readfile and writefile Api?
Thanks in advance. |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/4/2010 3:34:47 PM Posts: 167, Visits: 786 |
| | First you need to open the file with the CreateFile API, then you can use the WriteFile or WriteFileEx API to write to it. Good Luck |
| | | | Forum Newbie
       
Group: Forum Members Last Login: 6/10/2009 8:57:40 AM Posts: 7, Visits: 18 |
| 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 |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/4/2010 3:34:47 PM Posts: 167, Visits: 786 |
| | I think, could be wrong, that it has something to do with the overlapped flag you are passing. Do a reread on that in the help files. Good Luck |
| | | | Forum Guru
       
Group: Forum Members Last Login: 9/4/2010 3:34:47 PM Posts: 167, Visits: 786 |
| | |
|
|