Click or drag to resize

FRead4 Function

Read characters from a file into an allocated buffer.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.4a
Syntax
 FUNCTION FRead4(
	ptrHandle AS IntPtr,
	ptrBufferVar AS BYTE[],
	dwBytes AS DWORD,
	lAnsi AS LOGIC
) 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>. An array of bytes to store the data read from the specified file. The length of this variable must be greater than or equal to the number of bytes in the next parameter.
dwBytes
Type: UInt32
The number of bytes to read into the buffer.
lAnsi
Type: Boolean
If FALSE an OEM to ANSI conversion is made.

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
FRead4() is the same as FRead3(), except that it provides you with the option of doing an OEM to ANSI conversion.
Remarks
Tip Tip
Conversions between OEM en Ansi were relevant in an Ansi environment like Visual Objects. In a Unicode environment this conversion is noto much a conversion between OEM and Ansi but a conversion between either Unicode and Ansi or Unicode and OEM.
For these conversions the runtime uses the current values of the Windows Codepage and DOS Codepage.
Examples
This example uses FRead4() after successfully opening a file to read 128 bytes into a buffer area:
X#
 1DEFINE F_BLOCK := 128
 2Function Start()
 3    LOCAL cBuffer AS PTR
 4    cBuffer := MemAlloc(F_BLOCK)
 5    IF cBuffer = NULL PTR
 6        RETURN FALSE
 7    ENDIF
 8    ptrHandle := FOpen2("temp.txt", FO_READ)
 9    IF ptrHandle = F_ERROR
10        ? DOSErrString(FError())
11        RETURN FALSE
12    ELSE
13        IF FRead4(ptrHandle, cBuffer, F_BLOCK, FALSE) != F_BLOCK
14        ? DOSErrString(FError())
15            RETURN FALSE
16        ENDIF
17        FClose(ptrHandle)
18    ENDIF
19    MemFree(cBuffer)
20    RETURN TRUE
See Also