Click or drag to resize

FReadText3 Function

Read characters from a file into an allocated buffer, with possible OEM to ANSI conversion, based on the current SetAnsi() setting.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax
 FUNCTION FReadText3(
	ptrHandle AS IntPtr,
	ptrBufferVar AS BYTE[],
	dwBytes AS DWORD
) AS DWORD
View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to read from.
ptrBufferVar
Type: Byte
Pointer to an allocated buffer used to store data read from the specified file.  The length of this variable must be greater than or equal to <dwBytes>.
dwBytes
Type: UInt32
The number of bytes to read into the buffer.

Return Value

Type: UInt32
The number of bytes successfully read.  A return value less than <dwBytes> or 0 indicates end-of-file or some other read error.  FError() can be used to determine the specific error.
Remarks
FReadText3() is the same as FRead3(), except that an OEM to ANSI conversion is made when SetAnsi() is FALSE.
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()
Examples
This example uses FReadText3() after successfully opening a file to read 128 bytes into a buffer area:
X#
DEFINE F_BLOCK := 128
Function Start()
        LOCAL cBuffer AS PTR
        cBuffer := MemAlloc(F_BLOCK)
        IF cBuffer = NULL PTR
                RETURN FALSE
        ENDIF
        ptrHandle := FOpen("temp.txt")
        IF ptrHandle = F_ERROR
                ? DOSErrString(FError())
                RETURN FALSE
        ELSE
                IF FReadText3(ptrHandle, cBuffer, F_BLOCK) <> F_BLOCK
                        ? DOSErrString(FError())
                        RETURN FALSE
                ENDIF
                FClose(ptrHandle)
        ENDIF
        MemFree(cBuffer)
        RETURN TRUE
See Also