Utf8FromBuffer - cCharTranslate
Creates a UTF-8 string in a memory buffer from an OEM or ANSI memory buffer
Type: Function
Return Data Type: Pointer
Parameters
| Parameter | Type | Description |
|---|---|---|
| pMultiCharBuffer | Pointer | The address of a null terminated string |
| eCharType | Integer | The type of string encoding, which may be OEM (CP_OEMCP), ANSI (CP_ACP) or UTF-8 (CP_UTF8) |
Syntax
Function Utf8FromBuffer Pointer pMultiCharBuffer Integer eCharType Returns Pointer
Call Example
Get Utf8FromBuffer pMultiCharBuffer eCharType to PointerVariable
Description
Utf8FromBuffer creates a UTF-8 string in a memory buffer from an OEM or ANSI memory buffer.
The length of the returned UTF-8 string may be obtained using CStringLength(). This returns the number of bytes in the string, which may not be the same as the number of characters in the string.
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 Utf8FromBuffer and Utf8ToBuffer
Procedure TestUTF8Buffer
Address aVar aUTF8Buffer aVar2
Integer iVoid
String sVar sVar2
Move "Test String-Ññóí" to sVar
Move (AddressOf(sVar)) to aVar
// Move OEM to UTF8 buffer
Get Utf8FromBuffer of oCharTranslate aVar CP_OEMCP to aUTF8Buffer
// Note length of UTF-8 buffer is CStringLength(aUTF8Buffer)
// Move UTF8 Buffer to OEM String
Get Utf8ToBuffer of oCharTranslate aUTF8Buffer CP_OEMCP 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(aUTF8Buffer)) to iVoid
Move (Free(aVar2)) to iVoid
End_Procedure
Send TestUTF8Buffer
See Also
UTF8ToBuffer | UTF8FromStr | UTF8ToStr | Memory Management Functions
Return Value
The buffer address of the converted string