编程时
我有个函数是C编写的(编写起来很方便),转换成DLEPHI 就很繁,如下请问如何调用呢? 如果转换为DLEPHI 该怎么做呢
   //fcs是返回值,最开始是 0xffff 
   //cp是指向信息的指针,len是字节数,fcstab[]是事先定义好的数组从0..255
   Word fcs16(Word fcs, Byte *cp, Word len)
   {
while (len--)  
     fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
return fcs;
   }

解决方案 »

  1.   

    用BCB编译成.obj目标文件,用{$L test.obj}的方式静态链接,前面加上函数声明
      

  2.   

    function fcs16(fcs: Word; cp: PByte; len: Word): Word;
    begin
      while len=0 do
      begin
        fcs := (fcs shr 8) xor fcstab[(fcs xor cp^) and $FF];
        Inc(cp);
      end;
      Result := fcs;
    end;
      

  3.   

    function fcs16(fcs: Word; cp: PByte; len: Word): Word;
    begin
      while len<>0 do
      begin
        Dec(len);
        fcs := (fcs shr 8) xor fcstab[(fcs xor cp^) and $FF];
        Inc(cp);
      end;
      Result := fcs;
    end;