来自 Mikc lischke 的例子:
function StringToWideStringEx(const S: String
CodePage: Word): WideString;
var
L: Integer;
begin
L:= MultiByteToWideChar(CodePage, 0, PChar(S), -1, nil, 0);
SetLength(Result, L-1);
MultiByteToWideChar(CodePage, 0, PChar(S), -1, PWideChar(Result), L - 1);
end;
//---------------------------------------------------------------------
function WideStringToStringEx(const WS: WideString
CodePage: Word): String;
var
L: Integer;
begin
L := WideCharToMultiByte(CodePage, 0, PWideChar(WS), -1, nil, 0, nil, nil);
SetLength(Result, L-1);
WideCharToMultiByte(CodePage, 0, PWideChar(WS), -1, PChar(Result), L - 1, nil, nil);
end;