Function U8ToUnicode(szU8: PAnsiChar; var wszString: PWideChar): Integer;
Begin // UTF8 to Unicoderesult := 0;
if szU8 = nil then exit;
wszString := Pointer(LocalAlloc(0, lstrlenA(szU8) * 2 + 1));
FillChar(wszString^, lstrlenA(szU8) * 2, 0);
Utf8ToUnicode(wszString, szU8, lstrlenA(szU8));
result := 1;
end;
Function U8ToUnicode(szU8: PAnsiChar; var wszString: PWideChar): Integer;
Begin
result := 0;
result := MultiByteToWideChar(CP_UTF8, 0, szU8, lstrlenA(szU8), nil, 0);
wszString := Pointer(LocalAlloc(0, result + 1)); //wchar_t*
//轉換
MultiByteToWideChar(CP_UTF8, 0, szU8, lstrlenA(szU8), wszString, result);
//加上'/0'
if (result > 0) and (result < (lstrlenW(wszString) + 1)) then LstrcatW(wszString, ''#0);
result := 1;
MessageBoxW(0, wszString, '已轉換', MB_OK)
end;