Hi to all,
I discovered something odd about the way file is saved. I have a buffer that contains data, e.g.
05 45 6D 61 69 6C 0A 59 61 68 6F 6F 20 4D 6A 69 6C ; notice line feed ASCII code
When I create a file (using CreateFile) and write the data (WriteFile provided the relevant address and length of data to write), I ended up with an extra byte!
05 45 6D 61 69 6C 0D 0A 59 61 68 6F 6F 20 4D 6A 69 6C ; i.e. a CR is added before LF
If I change 0A to any other value, no problem occurs. I will try out WriteFileEx with CreateFile. Any comments would be useful.
Regards....newAsm
AFAIK WriteFile will not do this, no matter how the file is created or opened. Are you sure that the CR is actually being written to the file, and not being added by whatever you are using to view the data?
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
rlen dd 0
.radix 16
buff db 05,45,6D,61,69,6C,0A,59,61,68,6F,6F,20,4D,6A,69,6C,0,0,0
.radix 10
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
xor ebx, ebx
.WHILE ebx < SIZEOF buff
mov al, [buff+ebx]
print xbyte$(al)
.IF ebx < SIZEOF buff - 1
print chr$(",")
.ENDIF
inc ebx
.ENDW
print chr$(13,10)
invoke CreateFile,chr$("testdat.txt"),
GENERIC_READ or GENERIC_WRITE,
NULL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
mov ebx, eax
print "file handle "
print ustr$(ebx),13,10
invoke WriteFile, ebx, ADDR buff, SIZEOF buff, ADDR rlen, NULL
print "bytes written "
print ustr$(rlen),13,10
print "new file pointer "
invoke SetFilePointer,ebx, 0, 0, FILE_BEGIN
print ustr$(eax),13,10
invoke ReadFile, ebx, ADDR buff, SIZEOF buff, ADDR rlen, NULL
print "bytes read "
print ustr$(rlen),13,10
xor ebx, ebx
.WHILE ebx < SIZEOF buff
mov al, [buff+ebx]
print xbyte$(al)
.IF ebx < SIZEOF buff - 1
print chr$(",")
.ENDIF
inc ebx
.ENDW
print chr$(13,10)
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
5,45,6D,61,69,6C,A,59,61,68,6F,6F,20,4D,6A,69,6C,0,0,0
file handle 40
bytes written 20
new file pointer 0
bytes read 20
5,45,6D,61,69,6C,A,59,61,68,6F,6F,20,4D,6A,69,6C,0,0,0