BinaryPokeStr

Writes a string into a binary buffer.

Syntax:

BinaryPokeStr( handle, offset, string )

Parameters:

(i) handle: handle of buffer.

(i) offset: zero-based offset in the buffer to store string.

(s) string: string to store into buffer.

Returns:

(i)  number of bytes stored.

 

This function is used to write string data into a binary buffer. There must be sufficient space in the buffer between the offset and the allocated end of the buffer to accommodate the string.

Note: The string parameter may be composed of any characters except the null (00) character. If a null character is found, it will be assumed that the string ends at that point. If you need to store a null character into a binary buffer, use the BinaryPoke function.

 

Example:


; This example writes a new device= line to SYSTEM.INI
; It is *very* fast
NewDevice = "DEVICE=COOLAPP.386"
;
; Change to the Windows Directory
DirChange(DirWindows(0))
;
; Obtain filesize and allocate binary buffers
fs1=FileSize("SYSTEM.INI")
srcbuf = BinaryAlloc(fs1)
editbuf = BinaryAlloc(fs1+100)
;
; Read existing system.ini into memory
BinaryRead( srcbuf, "SYSTEM.INI")
;
; See if this change was already installed. If so, quit
a = BinaryIndexNc( srcbuf, 0, "COOLAPP.386", @FWDSCAN)
If a != 0 Then Goto AlreadyDone
;
; Find 386Enh section.
a = BinaryIndexNc( srcbuf, 0, "[386Enh]", @FWDSCAN)
;
;
; Find beginning of next line ( add 2 to skip over our crlf )
cuthere = BinaryIndexNc( srcbuf, a, @CRLF, @FWDSCAN) + 2
;
; Copy data from beginning of file to just after [386Enh}
; to the edit buffer
BinaryCopy( editbuf, 0, srcbuf, 0, cuthere)
;
; Add the device= line to the end of the edit buffer, and add a CRLF
BinaryPokeStr(editbuf,BinaryEodGet(editbuf), StrCat(NewDevice,@CRLF))
;
; Copy remaining part of source buffer to the edit buffer
a = BinaryEodGet(editbuf)
b = BinaryEodGet(srcbuf)
BinaryCopy( editbuf, a, srcbuf, cuthere, b-cuthere)
;
; Save file out to disk. Use system.tst until it is
; completely debugged
BinaryWrite( editbuf, "SYSTEM.TST")
;
; Close binary buffers
:AlreadyDone
BinaryFree(editbuf)
BinaryFree(srcbuf)
Message("BinaryPokeStr", "Done.")
See Also:

Binary Operations, BinaryCopy, BinaryPeek, BinaryPeekStr, BinaryPoke, BinaryPokeStrW