The built-in NSIS functions FileRead
/FileReadUTF16LE
and FileReadByte
can be used to read text and bytes but you can also call Windows functions directly. To read from a memory buffer you have to use the system struct syntax:
Section
InitPluginsDir
FileOpen $0 "$pluginsdir\test.txt" a
DetailPrint "NSIS:"
FileWrite $0 "Foo"
FileSeek $0 0 SET
FileRead $0 $1
DetailPrint |$1|
DetailPrint "System::Call:"
System::Alloc 100
Pop $1
System::Call '*$1(&m3 "Bar")' ; Write ASCII text into buffer using struct syntax
System::Call 'kernel32::WriteFile(i$0,i$1,i3,*i.r2,i0)i.r9'
DetailPrint "Write: OK=$9 ($2 bytes)"
System::Free $1
System::Call '*(&i100)i.r1' ; Alloc a 100 byte buffer using struct syntax
FileSeek $0 0 SET
System::Call 'kernel32::ReadFile(i$0,i$1,i6,*i.r2,i0)i.r9'
DetailPrint "Read: OK=$9 ($2 bytes)"
System::Call '*$1(&m${NSIS_MAX_STRLEN}.r2)' ; Read ASCII text into variable using struct syntax
System::Free $1
DetailPrint |$2|
FileClose $0
SectionEnd