Click or drag to resize

MemChr Function

Get a pointer to a matching character value in a memory buffer.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.6
Syntax
 FUNCTION MemChr(
	ptrBuffer AS IntPtr,
	dwChar AS BYTE,
	dwCount AS DWORD
) AS IntPtr
Request Example View Source

Parameters

ptrBuffer
Type: IntPtr
A pointer to the memory buffer to examine.
dwChar
Type: Byte
Word representation of the character to match.
dwCount
Type: UInt32
The number of characters in <ptrBuffer> to examine.

Return Value

Type: IntPtr
A pointer to the first occurrence of <dwChar> within the first <dwCount> characters of <ptrBuffer>.
If <dwChar> is not matched, MemChr() returns a NULL_PTR.
Remarks
Examples
This example uses MemChr() on a PSZ:
X#
1FUNCTION FindChar() AS VOID
2    LOCAL pszC1 := "ABCDEF" AS PSZ
3    ? MemChr(pszC1, ASC("A"), 6)            // A pointer
4    ? MemChr(pszC1, ASC("B"), 6)            // A pointer
5    ? MemChr(pszC1, ASC("B"), 1)
6    // NULL_PTR: ASC("B") is not in the
7    // first "1" characters of the PSZ
This next example uses MemChr() on an allocated block:
X#
 1FUNCTION FindChar2() AS VOID
 2    LOCAL ptrBuff := MemAlloc(10) AS PTR
 3    IF ptrBuff != NULL_PTR
 4        // Write 68 to first 10
 5        MemSet(ptrBuff, 68, 10)
 6        // Overwrite first 5 with 67
 7        MemSet(ptrBuff, 67, 5)
 8        ? MemChr(ptrBuff, 68, 10)            //3CEF:07DD
 9        ? MemChr(ptrBuff, 67, 10)            //3CEF:07D8
10    ENDIF
See Also