ZDecompressStr 使用出错

huayufei 2010-09-25 11:21:31
ZDecompressStr 传入一字符串变量,执行程序后,出现data error错误,已换最新版本的pas文件

网上搜索相关资料,没有找到

求教高手,帮忙看一下怎么回事?
...全文
231 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQ286251099 2010-10-05
  • 打赏
  • 举报
回复

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 吧
huayufei 2010-09-26
  • 打赏
  • 举报
回复
---------------------------
Testzip
---------------------------
Access violation at address 1000909D in module 'zlib1.dll'. Read of address FFFFFFFF.
---------------------------
确定
---------------------------
这是错误内容
huayufei 2010-09-26
  • 打赏
  • 举报
回复
楼上的兄弟,函数的原型是这样子的:
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;

出内存地址错误
huayufei 2010-09-25
  • 打赏
  • 举报
回复
跟踪代码,到下面函数
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
亮剑_ 2010-09-25
  • 打赏
  • 举报
回复
跟踪一下代码呢
bdmh 2010-09-25
  • 打赏
  • 举报
回复
老大,你那参数也没有字符串参数呀,你怎么传进去的
huayufei 2010-09-25
  • 打赏
  • 举报
回复
有人知道吗?帮个忙,给看看

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧