|
@@ -74,7 +74,7 @@ const
|
|
|
|
|
|
{ ANSI <-> Wide }
|
|
{ ANSI <-> Wide }
|
|
function AnsiToWideBuf(AnsiBuf: PChar; AnsiBufLen: longint; WideBuf: PWideChar; WideBufLen: longint): longint;
|
|
function AnsiToWideBuf(AnsiBuf: PChar; AnsiBufLen: longint; WideBuf: PWideChar; WideBufLen: longint): longint;
|
|
-function WideToAnsiBuf(WideBuf: PWideChar; WideBufLen: longint; AnsiBuf: PChar; AnsiBufLen: longint): longint;
|
|
|
|
|
|
+function WideToAnsiBuf(WideBuf: PWideChar; WideCharsLen: longint; AnsiBuf: PChar; AnsiBufLen: longint): longint;
|
|
function PCharToPWideChar(str: PChar; strlen: longint = -1; outlen: PLongInt = nil): PWideChar;
|
|
function PCharToPWideChar(str: PChar; strlen: longint = -1; outlen: PLongInt = nil): PWideChar;
|
|
function StringToPWideChar(const s: AnsiString; outlen: PLongInt = nil): PWideChar;
|
|
function StringToPWideChar(const s: AnsiString; outlen: PLongInt = nil): PWideChar;
|
|
|
|
|
|
@@ -333,10 +333,10 @@ begin
|
|
Result:=Result*SizeOf(WideChar);
|
|
Result:=Result*SizeOf(WideChar);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function WideToAnsiBuf(WideBuf: PWideChar; WideBufLen: longint; AnsiBuf: PChar; AnsiBufLen: longint): longint;
|
|
|
|
|
|
+function WideToAnsiBuf(WideBuf: PWideChar; WideCharsLen: longint; AnsiBuf: PChar; AnsiBufLen: longint): longint;
|
|
begin
|
|
begin
|
|
- Result := WideCharToMultiByte(CP_ACP, 0, WideBuf, WideBufLen, AnsiBuf, AnsiBufLen, nil, nil);
|
|
|
|
- if ((WideBufLen <> -1) or (Result = 0)) and (AnsiBuf <> nil) then
|
|
|
|
|
|
+ Result := WideCharToMultiByte(CP_ACP, 0, WideBuf, WideCharsLen, AnsiBuf, AnsiBufLen, nil, nil);
|
|
|
|
+ if ((WideCharsLen <> -1) or (Result = 0)) and (AnsiBuf <> nil) then
|
|
begin
|
|
begin
|
|
if Result + 1 > AnsiBufLen then
|
|
if Result + 1 > AnsiBufLen then
|
|
begin
|
|
begin
|
|
@@ -345,7 +345,7 @@ begin
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
AnsiBuf[Result] := #0;
|
|
AnsiBuf[Result] := #0;
|
|
- if (Result <> 0) or (WideBufLen = 0) then
|
|
|
|
|
|
+ if (Result <> 0) or (WideCharsLen = 0) then
|
|
Inc(Result);
|
|
Inc(Result);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -363,8 +363,10 @@ begin
|
|
begin
|
|
begin
|
|
len:=len*SizeOf(WideChar);
|
|
len:=len*SizeOf(WideChar);
|
|
GetMem(Result, len);
|
|
GetMem(Result, len);
|
|
- if (AnsiToWideBuf(str, -1, Result, len) = 0) and (strlen <> -1) then
|
|
|
|
|
|
+ len:=AnsiToWideBuf(str, strlen, Result, len);
|
|
|
|
+ if (len = 0) and (strlen <> -1) then
|
|
begin
|
|
begin
|
|
|
|
+ FreeMem(Result);
|
|
strlen:=-1;
|
|
strlen:=-1;
|
|
continue;
|
|
continue;
|
|
end;
|
|
end;
|
|
@@ -377,7 +379,7 @@ begin
|
|
break;
|
|
break;
|
|
end;
|
|
end;
|
|
if outlen <> nil then
|
|
if outlen <> nil then
|
|
- outlen^:=(len - 1)*SizeOf(WideChar);
|
|
|
|
|
|
+ outlen^:=len - SizeOf(WideChar);
|
|
end;
|
|
end;
|
|
|
|
|
|
function StringToPWideChar(const s: AnsiString; outlen: PLongInt = nil): PWideChar;
|
|
function StringToPWideChar(const s: AnsiString; outlen: PLongInt = nil): PWideChar;
|