Skip to content

Utf16ToStr - cCharTranslate

Creates a DataFlex String in OEM, ANSI or UTF8 format from a UTF-16 memory buffer

Type: Function
Return Data Type: String

Parameters

Parameter Type Description
pWideBuf Pointer The address of the UTF-16 string
eCharType Integer The type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)
iLen Integer The wide character length of the UTF-16

Syntax

Function Utf16ToStr Pointer pWideBuf Integer eCharType Integer iLen Returns String

Call Example

Get Utf16ToStr pWideBuf eCharType iLen to StringVariable

Description

Utf16ToStr creates a OEM, ANSI or UTF8 string from a UTF-16 memory buffer.

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 Utf16FromStr and Utf16ToStr
Procedure TestUTF16Str
    Address aUTF16Buffer
    Integer iLen iVoid
    String sVar sVar2

    Move "Test String-Ññóí" to sVar

    // Move OEM to UTF16 buffer
    Get Utf16FromStr of oCharTranslate sVar CP_OEMCP (&iLen) to aUTF16Buffer

    // Move UTF16 Buffer to OEM String
    Get Utf16ToBuffer of oCharTranslate aUTF16Buffer CP_OEMCP iLen to sVar2
    If (sVar<>sVar2) Begin
        Send Info_Box "Test Failed"
    End

    Move (Free(aUTF16Buffer)) to iVoid
End_Procedure

Send TestUTF16Str

See Also

UTF16FromBuffer | UTF16ToBuffer | UTF16ToStr | Memory Management Functions

Return Value

Returns the newly created string.