Shahriyar
Shahriyar

Reputation: 1583

C++ zLib compress byte array

I want to compress a byte array with zlib and here is my code :

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);
}

But ReturnCode always returns -2 (Z_STREAM_ERROR)
I took this code directly from zlib example codes (example.c), it works on its own example program and it returns 0 (Z_OK) there but in my program it returns -2
Any help would be appreciated

Upvotes: 0

Views: 2678

Answers (1)

Scott Jones
Scott Jones

Reputation: 2906

You need to allocate the compression buffer and send its size as the first two params, like so:

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

Upvotes: 3

Related Questions