Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Readfile/write file API


Readfile/write file API

Author
Message
Shreeti_Tula
Shreeti_Tula
Forum God
Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)

Group: Forum Members
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.
Edited
6/7/2009 by Shreeti_Tula
vb5prgrmr
vb5prgrmr
Forum God
Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)

Group: Forum Members
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

 

Shreeti_Tula
Shreeti_Tula
Forum God
Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)Forum God (1.8K reputation)

Group: Forum Members
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
vb5prgrmr
vb5prgrmr
Forum God
Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)

Group: Forum Members
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

 

vb5prgrmr
vb5prgrmr
Forum God
Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)Forum God (20K reputation)

Group: Forum Members
Posts: 167, Visits: 786
Hey, I found this...

 

http://www.vbforums.com/showthread.php?p=3536799

 

and it looks like what you are trying to do.

 

Good Luck

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search