the problem focuses on MASM and using Irvine 32 bits only. I don't plan to use macro or etc unless really needed.
.386
.model flat, stdcall
INCLUDE Irvine32.inc
.stack 4096
.Data
inputFilename byte "Enter filename : ",0
errorMssg byte "Unable to open file !",0
newAmount byte "2021",0 ;updated from dword to byte
fileHandle HANDLE ?
buffer dword 200 DUP(?)
.Code
main PROC
I would like to prompt user enter a filename. Then Open the file if it exist, if not error message is display. Lets assume the file is created and therefore exist. In the file contains just a number which is 2020.
OPEN_EXISTING_FILE:
mov edx,offset inputFilename ;ask user enter the existing filename
;currently in existing file content is 2020
call WriteString
call Crlf
mov ecx, SIZEOF inputFilename
call ReadString
call OpenInputFile
mov fileHandle,eax
;file error check
cmp eax, INVALID_HANDLE_VALUE
jne OVERWRITE_FILE
mov edx, offset errorMssg
call WriteString
call Crlf
jmp OPEN_EXISTING_FILE
It seems my Write to File is not working. Am i missing some codes? Can anyone guide me on how can i replace the "2020" to "2021", in the file.
OVERWRITE_FILE:
mov eax,fileHandle
mov edx, OFFSET newAmount ;i want to overwrite 2020 to 2021 in the existing file
mov ecx, LENGTHOF newAmount
call WriteToFile
call CloseFile
call crlf
call waitMsg
END main