Click or drag to resize

FReadStr Function

X#
Read characters from a file.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION FReadStr(
	ptrHandle AS IntPtr,
	dwBytes AS DWORD
) AS STRING
Request Example View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to read from.
dwBytes
Type: DWord
The number of bytes to read, beginning at the current DOS file pointer position. Characters are read up to dwBytes or until end-of-file is encountered.
The file pointer is then moved forward dwBytes.
If dwBytes is greater than the number of bytes from the pointer position to the end of the file, the file pointer is positioned at the last byte in the file.

Return Value

Type: String
A string.
A NULL_STRING indicates an error or end-of-file.
If end-of-file is reached while reading, FError() is set to 257.
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 displays the ASCII values of the first 16 bytes of a text file:
X#
1ptrHandle := FOpen2("new.txt", FC_NORMAL)
2IF ptrHandle = F_ERROR
3    ? DOSErrString(FError())
4ELSE
5    cString := FReadStr(ptrHandle, 16)
6    ? cString
7    FClose(ptrHandle)
8ENDIF
See Also