xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_Pointer2String()

Reads bytes from a pointer into a character string.

Syntax

HB_Pointer2String( <pPointer>, <nBytes> ) --> cString

Arguments

<pPointer>
This is a pointer value previously obtained from HB_String2Pointer().
<nBytes>
This is a numeric value specifying the number of bytes to read from the pointer.

Return

The function returns the a character string of <nBytes> length holding the bytes currently stored at the memory address <pPointer>.

Description

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.

Info

See also:C Structure class, HB_String2Pointer()
Category: Pointer functions , xHarbour extensions
Source:rtl\str2ptr.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe