Could someone show me how to read and write one byte at a time using the API?
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.
Ok, well how do i do that?
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