首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

C++ 转 delphi,10行!多谢先

2012-04-14 
C++ 转 delphi,10行!谢谢先!C/C++ codechar* hash_password_v1(const unsigned char* b0 , int b0len, con

C++ 转 delphi,10行!谢谢先!

C/C++ code
char* hash_password_v1(const unsigned char* b0 , int b0len, const unsigned char* password , int psdlen) {    unsigned char* dst = (unsigned char*)malloc(b0len + psdlen + 1);    unsigned char tmp[20];    char* res;    memset(tmp , 0 , sizeof(tmp));    memset(dst , 0 , b0len + psdlen + 1);    memcpy(dst , b0 , b0len);    memcpy(dst + b0len , password , psdlen);         tmp=..........//这行不管      free(dst);    res = hextostr(tmp , 20);    return res;}


[解决办法]
function hash_password_v1(b0: pansichar; b0len: integer; password: pansichar; psdlen: integer): pansichar;
var
dst,res,hex: pansichar;
tmp: array[0..19] of char;
begin
Getmem(dst,b0len + psdlen + 1);
fillchar(tmp,sizeof(tmp),0);
fillchar(dst,b0len + psdlen + 1,0);
move(b0^,dst^, b0len);
move(password^,Pointer(longword(dst)+b0len)^,psdlen);
// tmp=..........//这行不管

FreeMem(dst,strlen(dst)+1);
Getmem(hex,21);
fillchar(hex,21,0);
move(tmp,hex^,20);
Getmem(res,21);
fillchar(hex,21,0);
BintoHex(hex,res,20);
result := res; //注意返回内存记得释放

end;

热点排行