想写个程序,调用zlib1.dll压缩解压文件,但是老是弹出这个错误。不知道是dll本身的问题还是怎么回事?请高手解答,先说声谢谢,由于我是第一次提问,貌似没什么分送。源代码如下:implementation{$R *.dfm}function compress(infile:pointer;infilesize:integer;outfile:pointer;outfilesize:integer):integer;stdcall;external 'zlib1.dll';
function decompress(infile:pointer;infilesize:integer;ourfile:pointer;ourfilesize:integer):integer;stdcall;external 'zlib1.dll';
procedure TForm1.ButtoncompressClick(Sender: TObject);
var
 filehandle:integer;
 filelen:integer;
 buffer:pchar;
 outfile:pchar;
 outfilelen:integer;
begin
 if opendialog1.Execute then
  begin
   filehandle := fileopen(opendialog1.filename,fmopenread);
   filelen := fileseek(filehandle,0,2);
   fileseek(filehandle,0,0);
   buffer := pchar(allocmem(filelen+1));
   fileread(filehandle,buffer^,filelen);
   fileclose(filehandle);
   outfile := pchar(allocmem(filelen*4));
   outfilelen := filelen*2;
   compress(outfile,outfilelen,buffer,filelen);
  end;
 else
end; 
end.

解决方案 »

  1.   

    很快就沉底了。这个时间也这样?对了,我是在delphi7下调试的。错误发生在运行中。
      

  2.   

    呵呵 
    有压缩解压缩的控件啊
    挺好用的 还有Demo
      

  3.   

    提示不是全0,上面就是我的全部代码了。实在不知道哪里出错。dll是封装好的,从zlib.net下载的,c++编译的。会不会是参数错误啊。郁闷。
      

  4.   

    这是zlib手册里面关于这个函数的参数说明。
    int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
        Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.    This function can be used to compress a whole file at once if the input file is mmap'ed.    compress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer.