Could someone show me how to read and write one byte at a time using the API?
Posted on 2001-03-30 01:01:00 by HeroInc
I can but I won't: it's unadvisable to read/write file one byte at a time. The performance is awful. A better strategy is to read big chunks of the file into memory and deal with them one byte at a time.
Posted on 2001-03-30 02:37:00 by Iczelion
Ok, well how do i do that?
Posted on 2001-03-30 03:02:00 by HeroInc
read 10 bytes from file "test.dat" to buffer "filebuff"

.DATA
filename db "test.dat",0

.DATA?
fhandle dd ?
byteswr dd ?
filebuff db 10 dup(?)

.CODE
invoke CreateFile,addr filename,GENERIC_READ,0,+\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0

mov fhandle,eax

invoke ReadFile,fhandle,addr filebuff,10,addr byteswr,0      

invoke CloseHandle,fhandle
----------------------------------------------------------------- write 10 bytes from buffer "filebuff" to file "test.dat"

.DATA
filename db "test.dat",0
filebuff db "abcdefghij"

.DATA?
fhandle dd ?
byteswr dd ?


.CODE
invoke CreateFile,addr filename,GENERIC_WRITE,0,+\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0

mov fhandle,eax

invoke WriteFile,fhandle,addr filebuff,10,addr byteswr,0

invoke CloseHandle,fhandle     
----------------------------------------------------------------- check your api ref for further informations... good luck bye. This message was edited by drcmda, on 3/30/2001 4:40:17 AM
Posted on 2001-03-30 03:36:00 by drcmda