CopyMemoryToString - Transfer data from memory to a string

Top  Previous  Next

Syntax

<cString> := CopyMemoryToString( <nAddress>, [<nType>], [<nStringLen>], [@<nBytesRead>], [<lEmptyStringOnNull>] )

Parameters

<nAddress>

 

Start address of string in memory.

 

<nType>

 

Type of string data to be read from memory. See Cockpit string types for details. The default value is STRINGTYPE_BINARY.

 

<nStringLen>

 

Number of characters to be read. If this parameter is not specified, automatic size determination according to <nType> will take place.

 

<nBytesRead>

 

Number of bytes read during the operation.

 

<lEmptyStringOnNull>

 

This flag indicates if an empty string should be returned in case <nAddress> equals zero. If this flag is .F. (which is the default), NIL will be returned if <nAddress> equals zero.

Return value

String in Cockpit application character set that was found at address <nAddress>. If <nAddress> is 0, NIL or an empty string ("") is returned depending on <lEmptyStringOnNull>.

Description

A string starting in memory at <nAddress> is read and returned as a character value. During the transfer from memory to the returned string character set conversions will be performed according to <nType>. See Cockpit string types for details.

 

If a string length is not passed in <nStringLen>, termination is derived from <nType>. If STRINGTYPE_BINARY was passed for <nType> and no length information was given, a NULL-byte terminator is assumed. If a string length is not given, <nBytesRead> will include the terminator.

 

If a string length is passed in <nStringLen>, exactly this number of characters is read. The result is converted and trimmed according to the <nType> parameter before being returned. In this case <nBytesRead> will have the value of <nStringLen> or 2 * <nStringLen> for Unicode text strings on return.

 

If <nType> is STRINGTYPE_TEXT, STRINGTYPE_UNICODETEXT or STRINGTYPE_BINARY0, only the characters up to and not including the string terminator are read.

Classification

Core

Category

Pointers and memory

Quick Info

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

See also

CopyStringToMemory, SetCX, Character set conversion

Example

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "StringTypes.ch"

 

FUNCTION Main

 

LOCAL address

 

* Write a Unicode string to memory

address := LockString( Ansi2Unicode( "Here we go" ) )

 

* Read the string, convert from Unicode to Ansi, determine the length automatically

? CopyMemoryToString( address, STRINGTYPE_UNICODETEXT )

 

* Release the allocated memory

ReleaseLockString( address )

 

RETURN NIL