xHarbour Reference Documentation > Function Reference |
Reads bytes from a pointer into a character string.
HB_Pointer2String( <pPointer>, <nBytes> ) --> cString
The function returns the a character string of <nBytes> length holding the bytes currently stored at the memory address <pPointer>.
HB_Pointer2String() is the reverse function of HB_String2Pointer(). It reads <nBytes> bytes from memory and copies them into a character string, which is returned.
Warning: be cautious with reading bytes from a pointer. If the character string stored at the memory address <pPointer> has less than <nBytes> bytes, the result is unpredictable.
See also: | C Structure class, HB_String2Pointer() |
Category: | Pointer functions , xHarbour extensions |
Source: | rtl\str2ptr.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example converts a string to a pointer and reads // various numbers of bytes from memory. // The last line is an error to demonstrate the // unpredictable result when using HB_Pointer2String() // incorrectly. PROCEDURE Main LOCAL cString := "123456789" LOCAL pString := HB_String2Pointer( cString ) ? Valtype( cString ), cString ? Valtype( pString ), pString ? HB_Pointer2String( pString, 5 ) ? HB_Pointer2String( pString, 9 ) // This is an error!! ? HB_Pointer2String( pString, 15 ) RETURN
http://www.xHarbour.com