ZDecompressStr 传入一字符串变量,执行程序后,出现data error错误,已换最新版本的pas文件网上搜索相关资料,没有找到求教高手,帮忙看一下怎么回事?

解决方案 »

  1.   

    跟踪代码,到下面函数
    function ZDecompressCheck(code: Integer; raiseBufferError: Boolean = True): Integer;
    begin
      Result := code;  if code < 0 then
      begin
        if (code <> Z_BUF_ERROR) or raiseBufferError then
        begin
          raise EZDecompressionError.Create(code);
        end;
      end;
    end;code有时候为-3,有时候为-5
      

  2.   

    楼上的兄弟,函数的原型是这样子的:
    function  ZDecompressStr(const s: RawByteString): AnsiString;
    2#是这个函数调用的一个子函数,现在我已经知道问题出在什么地方了。是因为传入的数据是别人用C写的压缩数据,可能是版本或什么不一致造成的现在有一个问题,是这样的:这是C写的一个dll,调用函数如下:
    int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);uncompress 函数将 source 缓冲区的内容解压缩到 dest 缓冲区。sourceLen 是 source 缓冲区的大小(以字节计)。注意函数的第二个参数 destLen 是传址调用。当调用函数时,destLen 表示 dest 缓冲区的大小, dest 缓冲区要足以容下解压后的数据。在进行解压缩时,需要提前知道被压缩的数据解压出来会有多大。这就要求在进行压缩之前,保存原始数据的大小(也就是解压后的数据的大小)。这不是 zlib 函数库的功能,需要我们做额外的工作。当函数退出后, destLen 是解压出来的数据的实际大小。uncompress 若成功,则返回 Z_OK ;若没有足够内存,则返回 Z_MEM_ERROR;若输出缓冲区不够大,则返回 Z_BUF_ERROR。若输入数据有误,则返回 Z_DATA_ERROR。请高手给写一个在delphi中怎么定义,调用,我写的一直出错,如下:
      Function uncompress(dest:array of byte;destLen:Pint; source:array of byte;sourceLen:integer):integer;stdcall;external 'zlib1.dll'name'uncompress';调用部分
    var
      ss,ss1:string;
      stext:TStringList;
      Inarray,OutArray:array of byte;
      Re:Integer;
      OutLen:PINT;
    begin
      stext:=TStringList.Create;
      stext.LoadFromFile(ExtractFilePath(Application.ExeName)+'MNLLS.txt');
      ss:=DeleteSpace(stext.Text);
      ss1:=HexToStr(copy(ss,1,Length(ss)-2));
      SetLength(Inarray,Length(ss1));
      CopyMemory(@Inarray[0],@ss1[1],Length(ss1));
      //ShowMessage(IntToStr(Length(stext.Text)));
      if uncompress(OutArray,OutLen,Inarray,Length(ss1))=0 then
        ShowMessage('ok');
      stext.Free;出内存地址错误
      

  3.   

    ---------------------------
    Testzip
    ---------------------------
    Access violation at address 1000909D in module 'zlib1.dll'. Read of address FFFFFFFF.
    ---------------------------
    确定   
    ---------------------------
    这是错误内容
      

  4.   


    Function uncompress(dest:pbyte;var destLen:DWord; source:pbyte;sourceLen:integer):integer;stdcall;external 'zlib1.dll'name'uncompress';
    int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
    这好象没StdCall  吧