繁体   English   中英

C ++ zLib压缩字节数组

[英]C++ zLib compress byte array

我想用zlib压缩字节数组,这是我的代码:

void CGGCBotDlg::OnBnClickedButtonCompress()
{
   // TODO: Add your control notification handler code here
   z_const char hello[] = "hello, hello!";
   Byte *compr;
   uLong comprLen;

   int ReturnCode;
   uLong Length = (uLong)strlen(hello)+1;

   ReturnCode = compress(compr, &comprLen, (const Bytef*)hello, Length);
}

但是ReturnCode始终返回-2(Z_STREAM_ERROR)
我直接从zlib示例代码(example.c)中获取了此代码,它在自己的示例程序上运行,并在那里返回0(Z_OK),但在我的程序中它返回-2
任何帮助,将不胜感激

您需要分配压缩缓冲区并将其大小作为前两个参数发送,如下所示:

Byte compr[SomeReasonableSize];
uLong comprLen = sizeof(compr);
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM