16,471
社区成员
发帖
与我相关
我的任务
分享
bool packetM::UpdateFirstCmd(int len,QByteArray &strRec,int DevID)
strRec[7]=devID & 0xff;
strRec[8]=devID>>8 & 0xff;
if(3-i)
pos<<=8;
for(int i=0;i<4;i++)
strRec[13+i]=(char)(len>>(i*8) & 0xff);
lresult32=0;
lresult32=Crc32::GetCRC32((unsigned char *)strRec.constData(),17,lresult32);
QString strSend=strFile.mid(pos*2,len*2);
function UpdateFirstCmd(len:Integer;strRec:TBytes;DevID:Integer);
strRec[7]:=devID and $ff;
strRec[8]:=(devID shr 8) and $ff;
if(3-i)>0 then
pos:=pos shl 8;
for i:=0 to 3 do
strRec[13+i]:=len shr (i*8) and $ff;
lresult32:=0;
lresult32:=GetCRC32(@strRec[0],17,lresult32);
strSend := Copy(strFile,pos*2,len*2);
function UpdateFirstCmd(len:Integer;var strRec:TBytes;DevID:Integer): Boolean;
而且我找到一段Delphi代码,发现有两段代码功能是一样的,只是超出了我的理解范围。
var
pFakeB:pbyte;
pFakeB := pbyte(@lresult32);
strRec[17]:=pFakeB^;
Inc(pFakeB);
strRec[18]:= pFakeB^;
Inc(pFakeB);
strRec[19]:= pFakeB^;
Inc(pFakeB);
strRec[20]:= pFakeB^;
//上面代码和下面代码结果一样
strRec[17] :=lresult32 and $ff;
strRec[18] := lresult32 shr 8 and $ff;
strRec[19] := lresult32 shr 16 and $ff;
strRec[20] := lresult32 shr 24 and $ff;
lresult32=0;
lresult32=Crc32::GetCRC32((unsigned char *)strRec.constData(),17,lresult32);
QString strSend=strFile.mid(pos*2,len*2);
LRESULT :WIN32环境下Windows进程或者回调函数的返回值
Result:=0;
Result:=GetCRC32(@strRec[0],17,lresult32);
strSend := Copy(strFile,pos*2,len*2);
function UpdateFirstCmd(len:Integer;strRec:TBytes;DevID:Integer);
改为
function UpdateFirstCmd(len:Integer;strRec:TBytes;DevID:Integer): Boolean;