ts-soft's didn't actually work as it should when I tested here, here is fixed modified version which worked here (these functions does here both way):
Code: Select all
; UTF8 to Unicode/AscII (depend if the app is compiled as unicode or not).
Procedure.s Unicode(s.s)
Protected *Buffer
*Buffer = AllocateMemory(StringByteLength(S,#PB_UTF8) + 2) ;<== add a byte for the Null (1 or 2?)
PokeS(*Buffer,S, -1, #PB_Ascii)
Result$=PeekS(*Buffer, -1, #PB_UTF8)
FreeMemory(*Buffer)
ProcedureReturn Result$
EndProcedure
; Unicode/AscII (depend if the app is compiled as unicode or not) to UTf8.
Procedure.s UTF8(s.s)
Protected *Buffer
*Buffer = AllocateMemory(StringByteLength(S,#PB_UTF8) + 2) ;<== add a byte for the Null (1 or 2)?
PokeS(*Buffer,S, -1, #PB_UTF8);
Result$=PeekS(*Buffer, -1, #PB_Ascii);
FreeMemory(*Buffer)
ProcedureReturn Result$
EndProcedure
UTF8 is a ASCII formatted string using variable length for encodning the chars, hence it need to been "saved" to ASCII, and then convert it to a string using #PB_UTF8.