Click or drag to resize

Mem2String Function

X#
Extract a substring of a certain size from the left of a buffer.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION Mem2String(
	ptrSource AS IntPtr,
	dwCount AS DWORD
) AS STRING
Request Example View Source

Parameters

ptrSource
Type: IntPtr
Pointer to the buffer from which to extract the substring.
dwCount
Type: DWord
The number of bytes, from the left, to extract from ptrSource.

Return Value

Type: String
A substring of the specified number of bytes.
Remarks
Tip Tip
Contrary to normal PSZs, strings are not static and may be collected by the garbage collector.
Therefore, if you supply a string as an argument to a function, like Mem2String, which directly or indirectly allocates dynamic memory, you may run into trouble.
For example, in Mem2String(Time(), 5), Time() may cause problems. But Mem2String("hi there", 5) will not cause problems since literal strings are not collected.
Examples
This example uses Mem2String() to get the three leftmost characters of a PSZ:
X#
1LOCAL pszSource AS PSZ
2pszSource := "ABCDEF"
3? Mem2String(pszSource, 3)            // ABC
See Also