I have an .inf
file exported from Resource Hacker. The file is in UTF-16 LE encoding.
EXTRALARGELEGENDSII_INI TEXTFILE \"Data.bin\"
LARGEFONTSL
The file is in the UTF-16 LE encoding.
The LoadStringFromFile
does not support any Unicode encoding. It loads the file as is, to a byte array (the AnsiString
is effectively used as a byte array).
As the Unicode string
(in Unicode version of Inno Setup) actually uses the UTF-16 LE encoding, all you need to do is to copy the byte array bit-wise to the (Unicode) string
. And trim the UTF-16 LE BOM (FEFF
).
procedure RtlMoveMemory(Dest: string; Source: PAnsiChar; Len: Integer);
external 'RtlMoveMemory@kernel32.dll stdcall';
function LoadStringFromUTF16LEFile(FileName: string; var S: string): Boolean;
var
A: AnsiString;
begin
Result := LoadStringFromFile(FileName, A);
if Result then
begin
SetLength(S, Length(A) div 2);
RtlMoveMemory(S, A, Length(S) * 2);
{ Trim BOM, if any }
if (Length(S) >= 1) and (Ord(S[1]) = $FEFF) then
Delete(S, 1, 1);
end;
end;
See also Inno Setup Reading file in Ansi and Unicode encoding.