VariantStrToBuffer - cCharTranslate

Creates an OEM, ANSI or UTF8 string in a memory buffer from a Variant String

Type: Function

Return Data Type: Pointer

Parameters: Variant vValue Integer eCharType

ParameterDescription
vValueA Variant string
eCharTypeThe type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8)


Return Value

The string is converted to UTF-16 Unicode and placed in a newly created memory buffer. The buffer address is returned.


Syntax
Function VariantStrToBuffer Variant vValue Integer eCharType Returns Pointer

Call: Get VariantStrToBuffer vValue eCharType to PointerVariable


Description

VariantStrToBuffer creates a OEM, ANSI or UTF8 string in a memory buffer from a Variant String (the internal encoding of a Variant string is always Unicode).

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

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