Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update 2 bits in large files at given offsets. TOUGH?!?!

Status
Not open for further replies.

IonelBurtan

Programmer
May 25, 2001
601
RO
I want to update 2 bits in a large file at given offsets.
The big file is 8k paginated, and I also know in what page to make the update (

let us say that the absolute offset is 8196 in page 2 in the 1 Mb file. there i Have two bytes I want to overwrite with ascii characters 0 and 1.

How ca I Do that in VB. I have tried with MapViewOfFile, but I could not managed it to work.

Like that:
hFile = CreateFile...
hMap = CreateViewOfFile
hBaseMemory = MapViewOfFile
...
modify bytes with lstrcpy
...
UnmapViewOfFile hBaseMemory
CloseHandle hMap
CloseHandle hFile


any help apreciated,
tnx

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
just use the standard VB open/read/write using Binary file type.

see
just read up to the point of your absolute offset and get the byte which has the bit you are interested in flipping. update the bit/byte, output it, then continue.

you could probably also do it using Random access mode where you define a record of 1 byte length and then can read/write in place without having to create a new file.
 
Tnx, I'd like too, But i did not mentioned That I get the hFile from outsite (so the CreateFile call is made outside my code).
So, i think I must use some APIs for this job with HANDLE to the file (the standard write of visual basic does not know windows handles as far as I know).

I looked in WriteFile but I do not know how to write so that I do not increase the size of the file, that is not to make append but update of the bytes in question.

Ionel,
Any ideeas in this...?

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top