Click or drag to resize

MemByte Function

X#
Get a pointer to a byte in a memory buffer.

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

Parameters

ptrBuffer
Type: IntPtr
A pointer to the memory buffer to examine.
bChar
Type: Byte
The byte value to match.
dwCount
Type: DWord
The number of bytes in ptrBuffer to examine.

Return Value

Type: IntPtr
A pointer to the first occurrence of bChar within the first dwCount bytes of ptrBuffer.
If bChar is not matched, MemChr() returns a NULL_PTR.
Remarks
Examples
This example uses MemByte() on a PSZ:
X#
1FUNCTION FindChar()
2    LOCAL pszC1 := "ABCDEF" AS PSZ
3    ? MemByte(pszC1, ASC("A"), 6)            // 3F37:2788
4    ? MemByte(pszC1, ASC("B"), 6)            // 3F37:2789
5    ? MemByte(pszC1, ASC("B"), 1)            // 0000:0000
6    // NULL_PTR: ASC("B") is not in the
7    // first "1" characters of the PSZ
This example uses MemByte() on an allocated block:
X#
 1FUNCTION FindChar2()
 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        ? MemByte(ptrBuff, 68, 10)            // 3CA7:07DD
 9        ? MemByte(ptrBuff, 67, 10)            // 3CA7:07D8
10    ENDIF
11    MemFree(ptrBuff)
See Also