我有如下Delphi代码,请高手转换成VB代码,多谢!
目的:我现在写一个读取新中新第二代身份证阅读器的程序时,在繁体系统中读取出来的中文字为"?",想转换成繁体系统下能识别的中文字,刚在网上看到如下代码能实现.但不知怎么用VB实现.str 为unicode编码.
................... str:=GBToBig5(WideStringToString(str)); .....................
function GBToBig5(GBStr:String):AnsiString;
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936,0,pGBCHSChar,-1,nil,0);
GetMem(pGBCHTChar,Len*2+1);
ZeroMemory(pGBCHTChar,Len*2+1);
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
MultiByteToWideChar(936,0,pGBCHTChar,-1,pUniCodeChar,Len*2);
Len := WideCharToMultiByte(950,0,pUniCodeChar,-1,nil,0,nil,nil);
GetMem(pBIG5Char,Len);
ZeroMemory(pBIG5Char,Len);
WideCharToMultiByte(950,0,pUniCodeChar,-1,pBIG5Char,Len,nil,nil);
Result := String(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;
function WideStringToString(const WS: WideString; CodePage: Word): string;
var
InputLength,OutputLength:Integer;
begin
InputLength := Length(WS);
OutputLength := WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, nil, 0, nil, nil);
SetLength(Result, OutputLength);
WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, PChar(Result), OutputLength, nil, nil);
end;
目的:我现在写一个读取新中新第二代身份证阅读器的程序时,在繁体系统中读取出来的中文字为"?",想转换成繁体系统下能识别的中文字,刚在网上看到如下代码能实现.但不知怎么用VB实现.str 为unicode编码.
................... str:=GBToBig5(WideStringToString(str)); .....................
function GBToBig5(GBStr:String):AnsiString;
var
Len: Integer;
pGBCHTChar: PChar;
pGBCHSChar: PChar;
pUniCodeChar: PWideChar;
pBIG5Char: PChar;
begin
pGBCHSChar := PChar(GBStr);
Len := MultiByteToWideChar(936,0,pGBCHSChar,-1,nil,0);
GetMem(pGBCHTChar,Len*2+1);
ZeroMemory(pGBCHTChar,Len*2+1);
LCMapString($804,LCMAP_TRADITIONAL_CHINESE,pGBCHSChar,-1,pGBCHTChar,Len*2);
GetMem(pUniCodeChar,Len*2);
ZeroMemory(pUniCodeChar,Len*2);
MultiByteToWideChar(936,0,pGBCHTChar,-1,pUniCodeChar,Len*2);
Len := WideCharToMultiByte(950,0,pUniCodeChar,-1,nil,0,nil,nil);
GetMem(pBIG5Char,Len);
ZeroMemory(pBIG5Char,Len);
WideCharToMultiByte(950,0,pUniCodeChar,-1,pBIG5Char,Len,nil,nil);
Result := String(pBIG5Char);
FreeMem(pBIG5Char);
FreeMem(pGBCHTChar);
FreeMem(pUniCodeChar);
end;
function WideStringToString(const WS: WideString; CodePage: Word): string;
var
InputLength,OutputLength:Integer;
begin
InputLength := Length(WS);
OutputLength := WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, nil, 0, nil, nil);
SetLength(Result, OutputLength);
WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, PChar(Result), OutputLength, nil, nil);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货