Skip to content

Utf8ToBuffer - cCharTranslate

Creates an OEM or ANSI string in a memory buffer from a UTF-8 memory buffer

Type: Function
Return Data Type: Pointer

Parameters

Parameter Type Description
pMultiCharBuffer Pointer The address of a UTF-8 string
eCharType Integer The type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)

Syntax

Function Utf8ToBuffer Pointer pMultiCharBuffer Integer eCharType Returns Pointer

Call Example

Get Utf8ToBuffer pMultiCharBuffer eCharType to PointerVariable

Description

Utf8ToBuffer creates an OEM or ANSI string in a memory buffer from a UTF-8 memory buffer.

The length of the returned string may be obtained using CStringLength().

You are responsible for eventually disposing of the newly created memory buffer. This may be accomplished by using the Free function.

Use Windows.pkg
Use cCharTranslate.pkg

Object oCharTranslate is a cCharTranslate
End_Object

// test Utf8FromBuffer and Utf8ToBuffer
Procedure TestUTF8Buffer 
    Address aVar aUTF8Buffer aVar2
    Integer iVoid
    String sVar sVar2

    Move "Test String-Ññóí" to sVar
    Move (AddressOf(sVar)) to aVar

    // Move OEM to UTF8 buffer
    Get Utf8FromBuffer of oCharTranslate aVar CP_OEMCP to aUTF8Buffer
    // Note length of UTF-8 buffer is CStringLength(aUTF8Buffer)

    // Move UTF8 Buffer to OEM String
   Get Utf8ToBuffer of oCharTranslate aUTF8Buffer CP_OEMCP to aVar2
    // Note length of OEM buffer is CStringLength(aVar2)
    Move aVar2 to sVar2
    If (sVar<>sVar2) Begin
        Send Info_Box "Test Failed"
    End

    Move (Free(aUTF8Buffer)) to iVoid
    Move (Free(aVar2)) to iVoid
End_Procedure

Send TestUTF8Buffer

See Also

UTF8FromBuffer | UTF8FromStr | UTF8ToStr | Memory Management Functions

Return Value

The buffer address of the converted string