CopyStringToMemory - Transfer data from a string to memory

Top  Previous  Next

Syntax

 

<lRet> := CopyStringToMemory( <nAddress>, <cString>, [<nType>], [<nBufferSize>], [<nBytesWritten>] )

 

Parameters

 

<nAddress>

 

Target start address of string in memory.

 

<cString>

 

String to copy to the target address. In memory one 0-byte (STRINGTYPE_TEXT, STRINGTYPE_BINARY0) or two 0-bytes (STRINGTYPE_UNICODETEXT) are added. Strings of  STRINGTYPE_BINARY are not terminated.

 

<nType>

 

Type of string data to be written to memory. This value can be STRINGTYPE_BINARY, STRINGTYPE_BINARY0, STRINGTYPE_TEXT, STRINGTYPE_UNICODETEXT. Specifying this parameter requests character set conversions while copying the string data. Default is STRINGTYPE_BINARY.

 

<nBufferSize>

 

Size (number of bytes) of buffer available for the string and it's terminator. This parameter can be omitted if you are sure there is enough buffer space available. At least Len(<cString>) bytes are required to accommodate binary strings and Len(<cString>)+1 bytes for text strings and the terminating 0-byte. Unicode strings require 2* Len(<cString>)+2 bytes of memory. If <nBufferSize> is specified, <cString> is truncated if necessary to fit the buffer including its terminator.

 

<nBytesWritten>

 

OUT: Number of bytes written during the operation.

 

Return value

 

Always .T.

 

Description

 

A string is written to memory starting at address <nAddress>. During the transfer to memory character set conversions can be requested with <nType>. The conversions available are:

 

STRINGTYPE_BINARY

The bytes found at <nAddress> are copied without any conversion.

STRINGTYPE_BINARY0

The bytes found at <nAddress> are copied without any conversion.

STRINGTYPE_TEXT

The bytes found at <nAddress> are converted from Oem to Ansi if the characters set was set to Oem with SetOemConversion(.T.).

STRINGTYPE_UNICODETEXT

The bytes found at <nAddress> are converted from Oem to Unicode or Ansi character set depending on the current SetOemConversion setting.

       

 

In memory the string is terminated with one 0-byte (or two 0-bytes for Unicode strings). If a buffer size is specified, the string is truncated to fit into the buffer with termination.

 

Classification

 

Core

 

Category

 

Pointers and Memory

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

 

See also

 

CopyMemoryToString

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "StringTypes.ch"

 

FUNCTION Main

 

LOCAL address,sType

 

* Allocate memory (10 unicode characters = 20 bytes)

address := LockNullString(10,STRINGTYPE_UNICODETEXT)

 

* Copy a unicode string to memory, buffer size available is 20 bytes

* This will truncate the string to 9 characters because 2 bytes are necessary

* to terminate the string with two 0-bytes

CopyStringToMemory(address,"Here_goes_the_string",STRINGTYPE_UNICODETEXT,20)

 

* Read the string back from memory, only "Here_goes" will be displayed

? CopyMemoryToString(address,STRINGTYPE_UNICODETEXT)

 

* Release the allocated memory

ReleaseLockString( address )

 

RETURN NIL