C# and ZLib

B

Bien

Would someone mind helping me with a DllImport call to zlib 1.2.1?
I've tried several alternatives such as SharpZipLib, but they won't
work for what I'm doing. I have it sort of figured out, but it gives
errors sometimes such as "Object reference not set to an instance of
an object". I think it has something to do with zlib needing the
pointers to my variables, and I can't figure out how to give it the
pointer to a byte array. In the C++ header file for zlib the
uncompress function is listed as:

ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, const
Bytef *source, uLong sourceLen));

This was working, but was causing errors when extracting some files
like I said above:

[DllImport("zlib1.dll")]
static extern int uncompress(byte[] destBuffer, uint destLen, byte[]
sourceBuffer, uint sourceLen);

Thanks!
 
J

Jon Skeet [C# MVP]

Bien said:
Would someone mind helping me with a DllImport call to zlib 1.2.1?
I've tried several alternatives such as SharpZipLib, but they won't
work for what I'm doing. I have it sort of figured out, but it gives
errors sometimes such as "Object reference not set to an instance of
an object". I think it has something to do with zlib needing the
pointers to my variables, and I can't figure out how to give it the
pointer to a byte array. In the C++ header file for zlib the
uncompress function is listed as:

ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, const
Bytef *source, uLong sourceLen));

This was working, but was causing errors when extracting some files
like I said above:

[DllImport("zlib1.dll")]
static extern int uncompress(byte[] destBuffer, uint destLen, byte[]
sourceBuffer, uint sourceLen);

The destlen looks to me like it should be ref uint rather than uint,
given that the declaration has a pointer. I'm not an interop expert
though - I suggest if that doesn't work, you try in the .interop group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top