哪位C++高手帮助小弟将一段C++的代码转换成Delphi版的, 小弟万分感谢了!(12分)

  • 主题发起人 主题发起人 fftou
  • 开始时间 开始时间
F

fftou

Unregistered / Unconfirmed
GUEST, unregistred user!
int UGC( char * p, BYTE * out )
{
int i = 0;
int ilen = 0, olen = 0;
int iptr = 0, optr = 0;
BYTE * pb = (BYTE*)p;
BYTE b1,b2,b3,b4;
if( p == NULL || out == NULL)
return 0;
ilen = strlen( p );
if( ilen <= 0 )
return 0;
*((DWORD*)&p[ilen]) = 0x3c3c3c;
olen = (ilen * 6) / 8;
for( i =0;i < ((ilen + 3)/4);i ++ )
{
b1 = (pb[iptr++] - 0x3c) & 0x3f;
b2 = (pb[iptr++] - 0x3c) & 0x3f;
b3 = (pb[iptr++] - 0x3c) & 0x3f;
b4 = (pb[iptr++] - 0x3c) & 0x3f;
out[optr++] =(( b1 & b00111111) << 2 )| ((b2 & b00110000) >> 4);
out[optr++] =(( b2 & b00001111) << 4 )| ((b3 & b00111100) >> 2);
out[optr++] =(( b3 & b00000011) << 6 )| b4;
}
out[olen] = '/0';
return olen;
}
 
fuciton UGC( p:pchar;out:BYTE):integer
var
i,ilen,olen,iptr,optr:integer;
pb:^BYTE;
b1,b2,b3,b4:BYTE;
begin
i := 0;
ilen := 0;
olen := 0;
iptr := 0;
optr := 0;
pb := p;
if( p = nil) or (out = nil) then
begin
result:= 0;
end;
ilen := strlen( p );
if( ilen <= 0 )
return 0;
*((DWORD*)&p[ilen]) = 0x3c3c3c;
olen = (ilen * 6) / 8;
for( i =0;i < ((ilen + 3)/4);i ++ )
{
b1 = (pb[iptr++] - 0x3c) & 0x3f;
b2 = (pb[iptr++] - 0x3c) & 0x3f;
b3 = (pb[iptr++] - 0x3c) & 0x3f;
b4 = (pb[iptr++] - 0x3c) & 0x3f;
out[optr++] =(( b1 & b00111111) << 2 )| ((b2 & b00110000) >> 4);
out[optr++] =(( b2 & b00001111) << 4 )| ((b3 & b00111100) >> 2);
out[optr++] =(( b3 & b00000011) << 6 )| b4;
}
out[olen] = '/0';
return olen;
}

改了一点。
 
type
pbyte = ^byte;

function UGC(p: pchar; out: pbyte): Integer;
var
i, ilen, olen, iptr, optr: Integer;
pb: PByte;
b1, b2, b3, b4: Byte;
begin
i := 0;
ilen := 0;
olen := 0;
iptr := 0;
optr := 0;
pb := PByte(p);
Result := 0;
if (p = nil) or (out = nil) then
Exit;
ilen := strlen(p);
if (ilen <= 0) then
Exit;
//*((DWORD*)&p[ilen]) = 0x3c3c3c;
p^[iLen] := $00;
p^[iLen - 1] := $3c;
p^[iLen - 2] := $3c;
p^[iLen - 3] := $3c;
olen := (ilen * 6) div 8;
for i := 0 to ((ilen + 3) div 4) do
begin
b1 = (pb^[iptr] - 0x3c) and $3f;
inc(iptr);
b2 = (pb^[iptr] - 0x3c) and $3f;
inc(iptr);
b3 = (pb^[iptr] - 0x3c) and $3f;
inc(iptr);
b4 = (pb^[iptr] - 0x3c) and $3f;
inc(iptr);
out^[optr] =(( b1 and $3F) shl 2 ) or ((b2 and $30) shr 4);
inc(optr);
out^[optr] =(( b2 and $0F) shl 4 ) or ((b3 and $3C) shr 2);
inc(optr);
out^[optr] =(( b3 and $03) shl 6 ) or b4;
inc(optr);
end;
out^[olen] := 0;
Result := olen;
end;
 
to jerry529:
编译不能通过错误如下:
Array type required => p^[ilen] := $00;
能帮忙改一下吗谢谢了~
 
p^[ilen]
改為
p[ilen]^
呢?
 
试过了, 还是不行噢. 没人回答吗?
 
p^[ilen]改為p[ilen]呢?
 
后退
顶部