Utf16FromStr - cCharTranslate

Creates a UTF-16 string in a memory buffer from an OEM, ANSI or UTF-8 String variable

Type: Function

Return Data Type: Pointer

Parameters: String sValue Integer eCharType Integer ByRef iLen

ParameterDescription
sValueDataFlex string
eCharTypeThe type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)
iLen (ByRef)Returns the buffer's length in wide characters


Return Value

The buffer address, along with the buffer's length in wide characters, which is returned by reference in iLen.


Syntax
Function Utf16FromStr String sValue Integer eCharType Integer ByRef iLen Returns Pointer

Call: Get Utf16FromStr sValue eCharType (&iLen) to PointerVariable


Description

Utf16FromStr creates a UTF-16 string in a memory buffer from an OEM, ANSI or UTF-8 string.

You are responsible for eventually disposing of the newly created memory buffer.

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 | Free()