Utf16ToBuffer - cCharTranslate

Creates an OEM, ANSI or UTF8 string in a memory buffer from a UTF-16 memory buffer

Type: Function

Return Data Type: Pointer

Parameters: Pointer pWideBuf Integer eCharType Integer iLen

ParameterDescription
pWideBufThe address of the UTF-16 string
eCharTypeThe type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)
iLenThe wide character length of the UTF-16 string


Return Value

The buffer address.


Syntax
Function Utf16ToBuffer Pointer pWideBuf Integer eCharType Integer iLen Returns Pointer

Call: Get Utf16ToBuffer pWideBuf eCharType iLen to PointerVariable


Description

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

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 Utf16FromBuffer and Utf16ToBuffer
Procedure TestUTF16Buffer 
    Address aVar aUTF16Buffer aVar2
    Integer iLen iVoid
    String sVar sVar2

    Move "Test String-Ññóí" to sVar
    Move (AddressOf(sVar)) to aVar
 
    // Move OEM to UTF16 buffer
    Get Utf16FromBuffer of oCharTranslate aVar CP_OEMCP (&iLen) to aUTF16Buffer
    
    // Move UTF16 Buffer to OEM String
    Get Utf16ToBuffer of oCharTranslate aUTF16Buffer CP_OEMCP iLen 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(aUTF16Buffer)) to iVoid
    Move (Free(aVar2)) to iVoid
End_Procedure
 
Send TestUTF16Buffer

See Also

UTF16FromBuffer | UTF16FromStr | UTF16ToStr | Free()