i have library developed in c decompresses lzma encoded file. signature file pointer data, compressed, decompressed, , 'out' field error code. return value pointer array (or null if fails).
the function in c looks similar this:
char* decompresslzma(const char *lzmadata, int compressedsize, int uncompressedsize, t_status_codes *statuscode);
i've tried using pointers , memory other examples not working.
how pass byte array , pointer in data back?
this interface:
public interface lzmalibrary extends library { memory lzma_uncompress(memory lzma_data, int compressed_size, int uncompressed_size, pointer status_code); }
it appears wanted make pointer of 'memory' class instead. solution working me right create pointer objects, , library fill pointers, , them , handle appropriately.
my interface turned to:
public interface lzmalibrary extends library { pointer lzma_uncompress(pointer lzma_data, int compressed_size, int uncompressed_size, pointer status_code); }
from there able write in data:
pointer ptr = new memory(lzmadata.length); ptr.write(0, lzmadata, 0, lzmadata.length);
i need pointer written to:
pointer errorstatus = new memory(4);
then can call function pointer back, , read pointer if it's not null:
pointer p = lzmalib.lzma_uncompress(ptr, lzmadata.length, decompressed_length, errorstatus); // decompressed_length constant. if (p != null) { byte[] decompresseddata = p.getbytearray(0, decompressed_length); system.out.println(new string(decompresseddata, "ascii")); // data ascii text. } if (errorstatus != null) { int errorstatuscode = errorstatus.getint(0); system.out.println("error code: " + errorstatuscode); }
this appears have solved problem. new jna not missing anything.
if there's possible errors might run into, please feel free post on how correct it.