Q
QSmile
Unregistered / Unconfirmed
GUEST, unregistred user!
做了两个函数, AnsiToUnicode 与 UnicodeToAnsi 哪位能帮我测试下对不对?
function AnsiToUnicode(s:string):WideString;
var
lpWideCharWideChar;
len:Integer;
begin
len := ( Length(s) + 1 ) * 2;
GetMem(lpWideChar, len);
ZeroMemory(lpWideChar, len);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,
PChar(s), Length(s),lpWideChar, Len);
Result := lpWideChar;
FreeMem(lpWideChar);
end;
function UnicodeToAnsi(s:WideString):string;
var
lpCharChar;
len:integer;
begin
len := Length(s) * 2;
GetMem(lpChar,len);
ZeroMemory(lpChar, len);
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, PWideChar(s),
Length(s),lpChar,Len, nil, nil );
Result := lpChar;
FreeMem(lpChar);
end;
function AnsiToUnicode(s:string):WideString;
var
lpWideCharWideChar;
len:Integer;
begin
len := ( Length(s) + 1 ) * 2;
GetMem(lpWideChar, len);
ZeroMemory(lpWideChar, len);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,
PChar(s), Length(s),lpWideChar, Len);
Result := lpWideChar;
FreeMem(lpWideChar);
end;
function UnicodeToAnsi(s:WideString):string;
var
lpCharChar;
len:integer;
begin
len := Length(s) * 2;
GetMem(lpChar,len);
ZeroMemory(lpChar, len);
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, PWideChar(s),
Length(s),lpChar,Len, nil, nil );
Result := lpChar;
FreeMem(lpChar);
end;