Skip to content

VariantStrFromBuffer - cCharTranslate

Creates a Variant String from an OEM, ANSI or UTF-8 memory buffer

Type: Function
Return Data Type: Variant

Parameters

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

Syntax

Function VariantStrFromBuffer Pointer pSource Integer eCodeType Returns Variant

Call Example

Get VariantStrFromBuffer pSource eCodeType to VariantVariable

Description

VariantStrFromBuffer creates a Variant String from an OEM, ANSI or UTF-8 memory buffer.

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

See discussion in the cCharTranslate class overview about the advantages and disadvantage of using the Variant String type.

Use Windows.pkg
Use cCharTranslate.pkg

Object oCharTranslate is a cCharTranslate
End_Object

Procedure TestVariantBuffer1 
    Address aUTF8Buffer
    Integer iVoid
    Variant vVar vVar2

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

    // Move Variant (utf-16) to utf-8 buffer
    Get VariantStrToBuffer of oCharTranslate vVar CP_UTF8 to aUTF8Buffer

    // Move UTF8 Buffer to variant (utf-16)
    Get VariantStrFromBuffer of oCharTranslate aUTF8Buffer CP_UTF8 to vVar2
    If (vVar<>vVar2) Begin
        Send Info_Box "Test Failed"
    End

    Move (Free(aUTF8Buffer)) to iVoid
End_Procedure

Send TestVariantBuffer1

See Also

VariantStrToBuffer | VariantStrFromStr | VariantStrToStr | VariantStrFromUTF16 | VariantStrToUTF16 | Free()

Return Value

The string is converted to UTF-16 Unicode and returned it as a Variant string