Better would be using MultiByteToWideChar since the text contains chars not used in latin/portuguese
Do you have some example of it using MultiByteToWideChar and WideCharToMultiByte
I built one years ago for AnsitoUTF8, but never did the reverse operation, and don´t know how to do it:
The AnsitoUTF8, i ported was like this (RosAsm syntax):
Proc AnsitoUTF8Masm:
Arguments @pszAscii, @pszUTF8, @BomFlag
Local @lenASCII, @lenUCS2, @lenUTF8, @pszUCS2, @pUnicode, @LenCharString, @lenUTF8Result
Uses ecx, edi, edx
xor eax eax
On D@pszAscii = 0, ExitP
On D@pszUTF8 = 0, ExitP
mov edi D@pszUTF8
; length of pszUTF8 must be enough; its maximum is (lenASCII*3 + 1)
call StrLenProc D@pszAscii
If eax = 0
mov B$edi 0 | ExitP
End_If
mov ecx eax
shl eax 1
add eax ecx
inc eax
call 'RosMem.VMemAlloc' edi, eax
If eax = 0
mov B$edi 0 | ExitP
End_If
mov D@pUnicode eax
mov D@LenCharString ecx
inc ecx
call 'KERNEL32.MultiByteToWideChar' &CP_ACP, &MB_PRECOMPOSED, D@pszASCII, D@LenCharString, D@pUnicode, ecx
mov D@lenUCS2 eax
call UTF8Length D@pUnicode, eax
mov D@lenUTF8 eax
If D@BomFlag = &TRUE
add eax 3
End_If
mov D@lenUTF8Result eax
mov edi D@pszUTF8
call 'RosMem.VMemAlloc' D@pszUTF8, eax
If eax = 0
mov B$edi 0
call 'RosMem.VMemFree' D@pUnicode | ExitP
End_If
If D@BomFlag = &TRUE
mov D$eax 0BFBBEF
add eax 3
End_If
;length of pszUTF8 must be >= (lenUTF8 + 1)
call 'KERNEL32.WideCharToMultiByte' &CP_UTF8, 0, D@pUnicode, D@LenCharString, eax, D@lenUTF8, 0, 0
call 'RosMem.VMemFree' D@pUnicode
mov eax D@lenUTF8Result
mov ecx D$edi
add ecx eax | mov B$ecx 0
EndP