码迷,mamicode.com
首页 > Windows程序 > 详细

delphi7 string 转到 PWideChar 用于连接unicode dll调用

时间:2017-12-25 13:40:24      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:ide   compose   pch   res   osi   byte   char   length   rom   

function UnicodeToAnsi(s: WideString): string;
var
lpChar: PChar;
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
lpWideChar: PWideChar;
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;

delphi7 string 转到 PWideChar 用于连接unicode dll调用

标签:ide   compose   pch   res   osi   byte   char   length   rom   

原文地址:http://www.cnblogs.com/maweiwei/p/8108619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!