N
nec
Unregistered / Unconfirmed
GUEST, unregistred user!
在网上找到以下资料可惜试过不行.请高手指教具体PDU中文解码代码.
function UnicodeToString(var AString: string; AUnicode: PChar; ALenth: integer): integer;
var
TmpBuf: array [1..1024] of char;
TmpChar: char;
TmpLen, i: integer;
begin
try
TmpLen := ALenth div 2;
if ALenth > 0 then
begin
CopyMemory(@TmpBuf, AUnicode, ALenth);
for i := 0 to TmpLen - 1 do
begin
TmpChar := (AUnicode + i * 2)^;
(AUnicode + i * 2)^ := (AUnicode + i * 2 + 1)^;
(AUnicode + i * 2 + 1)^ := TmpChar;
end;
TmpBuf[TmpLen * 2 + 1] := #0;
TmpBuf[TmpLen * 2 + 2] := #0;
AString := WideCharToString(pwidechar(AUnicode));
Result := TmpLen;
end
else
begin
Result := 0;
end;
except
AString := '';
Result := 0;
end;
end;
function UnicodeToString(var AString: string; AUnicode: PChar; ALenth: integer): integer;
var
TmpBuf: array [1..1024] of char;
TmpChar: char;
TmpLen, i: integer;
begin
try
TmpLen := ALenth div 2;
if ALenth > 0 then
begin
CopyMemory(@TmpBuf, AUnicode, ALenth);
for i := 0 to TmpLen - 1 do
begin
TmpChar := (AUnicode + i * 2)^;
(AUnicode + i * 2)^ := (AUnicode + i * 2 + 1)^;
(AUnicode + i * 2 + 1)^ := TmpChar;
end;
TmpBuf[TmpLen * 2 + 1] := #0;
TmpBuf[TmpLen * 2 + 2] := #0;
AString := WideCharToString(pwidechar(AUnicode));
Result := TmpLen;
end
else
begin
Result := 0;
end;
except
AString := '';
Result := 0;
end;
end;