A variant of the previous example, with a Mid$() macro:
include \Masm32\MasmBasic\Res\JBasic.inc
Mid$ MACRO pString, mStart, mBytes
mov rdx, repargA(pString)
mov rax, mStart
add rax, rdx
mov rdx, mBytes
and byte ptr [rax+rdx], 0
EXITM <rax>
ENDM
Init ; OPT_64 1 ; 0 for 32 bit, 1 for 64 bit assembly
PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
Open "A", #1, "TestO.txt" ; append to existing file
Print "Hello world", CrLf$, "take it easy", Str$(" \nThe file handle is %i\n\n", rax)
Print #1, "Strings", CrLf$, "written to a file:", CrLf$, "the entry point is at ", Hex$(offset start), CrLf$
Close #1
PrintLine "The content of the file: ", CrLf$, "[", FileRead$("TestO.txt"), "]"
MsgBox 0, Mid$(FileRead$("\Masm32\include\Windows.inc"), 92, 1036), "Hi", MB_OK
EndOfCode
Source and executables attached. You may note that the 64-bit executable is somewhat larger (4096 bytes) than the 32-bit exe (2560 bytes).