LockString - Allocate memory and fill it with data

Top  Previous  Next

Syntax

 

<nAddress> := LockString( <cData>, [<nType] )

 

Parameters

 

<cData>

 

String to be committed to memory.

 

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

 

Return value

 

The memory address where <cData> starts.

 

Description

 

LockString allocates a memory block for <cData> and writes the string contained in <cdata> to that block. LockString always adds two 0-bytes in memory at the end of the string. This makes sure a C text string or a Unicode C text string is properly terminated.

 

To release the allocated memory block, use UnlockString or ReleaseLockString passing the returned address.

 

Classification

 

Core

 

Category

 

Pointers and Memory

 

Quick Info        

 

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

 

See also

 

LockNullString, LockStringLen, UnlockString, ReadLockString, ReleaseLockString

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "StringTypes.ch"

 

FUNCTION Main

 

LOCAL address

 

* Lock a Unicode string in memory

address := LockString( "Here we go.", STRINGTYPE_UNICODETEXT )

 

* Get the length of the string (number of characters)

? "Length: ",LockStringLen(address)

 

* Get the allocated size of the string (number of bytes)

? "Size: ",LockStringSize(address)

 

IF LockStringType(address) == STRINGTYPE_UNICODETEXT

  ? "It's a Unicode string"

ELSE

  ? "It's not a Unicode string"

ENDIF

 

* Read the string and free the allocated memory

? UnlockString(address)

 

RETURN NIL