Click or drag to resize

FWrite Function (IntPtr, String, DWord)

X#
Write a string to an open file.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION FWrite(
	ptrHandle AS IntPtr,
	cBuffer AS STRING,
	nBytes AS DWORD
) AS DWORD
Request Example View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to write to.
cBuffer
Type: String
The string to write.
nBytes
Type: DWord
The number of bytes in cBuffer to write, beginning at the current file pointer position.
If omitted, the entire contents of cBuffer is written.

Return Value

Type: DWord
The number of bytes written.
If the value returned is equal to nBytes, the operation was successful.
If the return value is less than nBytes or 0, this means that the length of cBuffer is less than nBytes, or the disk is full, or another error has occurred. FError() can be used to determine the specific error. When a disk full error occurs, FError() is set to 256. FWrite() and FWrite3 are assumed to handle raw binary data and are not dependent upon the status of SetAnsi(). FWriteText() and FWrite4(), on the other hand, are dependent upon SetAnsi().
Remarks
Remarks
Tip Tip
The low level File IO functions in the X# runtime are using .Net filestreams in the background.
That means that the file handles returned by FOpen() and FCreate() are not 'normal' file handles, but unique identifiers that are used to find the underlying stream object in a collection of streams in the runtime.
That also means that you can't use file handles for functions such as FRead() and FWrite() that were not created in the X# runtime.
If you want to access the underlying FileStream, then you should call the function FGetStream(IntPtr)
Examples
This example copies the contents of one file to another:
X#
 1DEFINE F_BLOCK := 512
 2...
 3cBuffer := Space(F_BLOCK)
 4nInfile := FOpen2("temp.txt", FO_READ)
 5nOutfile := FCreate("newfile.txt", FC_NORMAL)
 6lDone := FALSE
 7DO WHILE !lDone
 8    nBytesRead := FRead(nInfile, @cBuffer,;
 9    F_BLOCK)
10    IF FWrite(nOutfile, cBuffer) < SLen(cBuffer)
11        ? DOSErrString(FError())
12        lDone := TRUE
13    ELSE
14        lDone := (nBytesRead = 0)
15    ENDIF
16ENDDO
17FClose(nInfile)
18FClose(nOutfile)
See Also