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.08
Syntax
 FUNCTION MemChr(
	ptrBuffer AS IntPtr,
	dwChar AS BYTE,
	dwCount AS DWORD
) AS IntPtr
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#
FUNCTION FindChar() AS VOID
        LOCAL pszC1 := "ABCDEF" AS PSZ
        ? MemChr(pszC1, ASC("A"), 6)                        // A pointer
        ? MemChr(pszC1, ASC("B"), 6)                        // A pointer
        ? MemChr(pszC1, ASC("B"), 1)
        // NULL_PTR: ASC("B") is not in the
        // first "1" characters of the PSZ
This next example uses MemChr() on an allocated block:
X#
FUNCTION FindChar2() AS VOID
        LOCAL ptrBuff := MemAlloc(10) AS PTR
        IF ptrBuff != NULL_PTR
                // Write 68 to first 10
                MemSet(ptrBuff, 68, 10)
                // Overwrite first 5 with 67
                MemSet(ptrBuff, 67, 5)
                ? MemChr(ptrBuff, 68, 10)                        //3CEF:07DD
                ? MemChr(ptrBuff, 67, 10)                        //3CEF:07D8
        ENDIF
See Also