News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

CreateFile,ReadFile, & WriteFile

Started by BrWarburto, February 16, 2005, 05:39:24 PM

Previous topic - Next topic

BrWarburto

Many thanks to Jeremy & Vortex for help with CreateFile. For those who have found these fairly incomprehensible the following example will read into buffer and copy from a named file to another named file up to 200k long. It also works quite happily inside GoBug. Vortex's 'CommandLine' subroutine could also be incorporated to read in and read out files on the fly. Comments welcome!
:dance

;*  General GoAsm type programme   A:\in_out01.asm 16-02-2005    16-55-28           */
;*  General GoAsm type programme   A:\in_out01.asm 16-02-2005    16-47-52           */
;*  General GoAsm type programme   A:\in_out01.asm 12-02-2005    20-14-14           */
;*  General GoAsm type programme   A:\in_out01.asm 12-02-2005    18-52-43           */
;*  General GoAsm type programme   A:\in_out01.asm 12-02-2005    18-38-51           */
;*  General GoAsm type programme   A:\in_out01.asm 12-02-2005    18-35-54           */
;System tested using GOBUG 12-02-05. Input file successfully opened and read.
;Data memory read by GOBUG and gives confirmation that file was actually
;read in!
;Data successfully written to 'outfile' to the correct extent  16-02-2005.
DATA SECTION
RCKEEP DD 0
SzBuffer db 200000D DUP 00
SzInFile DB 'A:infile',0
SzOutFil DB 'A:outfile',0
SzOkMess DB 'Valid File Handle ready',0dh,0ah,0
SzFileSize DB 'No. of Bytes in Infile was: %d',0dh,0ah,0
SzWorkStr DB '                                                   ',0
CODE SECTION
START:
PUSH 0,80h,3
PUSH 0,1h,80000000h
PUSH ADDR SzInFile
CALL CreateFileA
CMP EAX,-1
JNE > .fin
RET
.fin
PUSH EAX
INVOKE wsprintfA, ADDR SzWorkStr,ADDR SzOkMess
ADD esp,8d
CALL PRNTFL
POP EAX
PUSH EAX
PUSH 0,ADDR RCKEEP
PUSH 200000D,ADDR SzBuffer
PUSH EAX
CALL ReadFile
INVOKE wsprintfA, ADDR SzWorkStr,ADDR SzFileSize,[RCKEEP]
PUSH [RCKEEP]
ADD esp,12d
CALL PRNTFL
POP [RCKEEP]
POP EAX
;MOV EAX,0
PUSH EAX
CALL CloseHandle
OUTFILE:
PUSH [RCKEEP]
PUSH 0,80h,2h
PUSH 0,1h,0C0000000h
PUSH ADDR SzOutFil
CALL CreateFileA
CMP EAX,-1
JNE > .fin2
RET
.fin2
PUSH EAX
INVOKE wsprintfA, ADDR SzWorkStr,ADDR SzOkMess
ADD esp,8d
CALL PRNTFL
POP EAX
POP [RCKEEP]
PUSH EAX
PUSH 0,ADDR RCKEEP
PUSH [RCKEEP],ADDR SzBuffer
PUSH EAX
CALL WriteFile
POP EAX
PUSH EAX
CALL CloseHandle
RET



PRNTFL:
MOV [RCKEEP],EAX
PUSH -11D
CALL GetStdHandle
PUSH 0,ADDR RCKEEP
PUSH [RCKEEP],ADDR SzWorkStr
PUSH EAX
CALL WriteFile
RET