Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » API » Readfile/write file API


Readfile/write file APIExpand / Collapse
Author
Message
Posted 6/8/2009 2:23:32 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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.
Post #27762
Posted 6/8/2009 11:40:58 PM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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

 

Post #27765
Posted 6/9/2009 3:05:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #27767
Posted 6/10/2009 4:34:56 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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

 

Post #27774
Posted 6/12/2009 2:16:10 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 9/4/2010 3:34:47 PM
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

Post #27787
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 2:11pm