i have the dllimport
[DllImport("../../zlib-1.2.5/zlib1.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int uncompress(byte[] destBuffer, ref uint destLen, byte[] sourceBuffer, uint sourceLen);
and call it like
uint _dLen = (uint) 8192;
byte[] data = compressed_data;
byte[] _d = new byte[_dLen];
if (uncompress(_d, ref _dLen, data, (uint)data.Length) != 0)
return null;
the uncompress function in zlib looks like
unsigned int ZEXPORT uncompress (dest, destLen, source, sourceLen)
unsigned char *dest;
Uint32 destLen;
unsigned char *source;
Uint32 sourceLen;
{
z_stream stream;
int err;
stream.next_in = source;
stream.avail_in = sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((Uint32)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest;
stream.avail_out = destLen;
if ((Uint32)stream.avail_out != destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
err = inflateInit(&stream);
if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
err = inflateEnd(&stream);
return stream.total_out;
}
but i always end up receiving a null in the c# side.
edit: The error is the z_data_error.
edit2: Z_DATA_ERROR if the input data was corrupted.
do i need to marshall the byte[] array to unmanaged pointers?
Or what could be the problem? Is my input array not valid?
best regards
After more and more research i get the feeling that everything is right here,
and the error must be elsewhere.