0
我一直在嘗試讀取在.txt文件中寫入的字符串,並在控制檯上將其打印出來。但是,我似乎做得不對。有人可以查看我的代碼並告訴我發生了什麼問題嗎?謝謝!masm32 ReadFile函數x86 -Windows
include \masm32\include\masm32rt.inc
.data
txtFilter db "*.txt",0
txtFD WIN32_FIND_DATA <>
txtHandle HANDLE ?
fHandle HANDLE ?
bufferLength db ?
buffer db 5000 dup(?)
lnt db "1024",0
okay db "Okay!",0
dokay db "Dokay!",0
.code
start:
push offset txtFD
push offset txtFilter
call FindFirstFile
mov txtHandle, eax
push offset txtFD.cFileName
call StdOut
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push FILE_APPEND_DATA
push offset txtFD.cFileName
call CreateFile
.if eax == INVALID_HANDLE_VALUE
jmp _error
.else
mov fHandle, eax
.endif
push 0
push offset bufferLength
push offset lnt
push offset buffer
push fHandle
call ReadFile
jmp _next
_error:
push offset dokay
call StdOut
jmp _next
_okay:
push offset okay
call StdOut
_next:
push offset buffer
call StdOut
push fHandle
call CloseHandle
push txtHandle
call FindClose
push 0
call ExitProcess
end start
該代碼似乎無法讀取我的txt文件中的內容。不過,我可以成功地搜索我的txt文件,並執行函數CreateFile
當你調用ReadFile的你是推'偏移lnt'而不僅僅是'lnt'。 'nNumberOfBytesToRead'參數是按值傳遞的,而不是按地址傳遞的。 –
我也懷疑你必須提供'lnt'作爲ascii字符串的長度。我會嘗試'lnt dd 1024' – Tommylee2k