JNA, Mapping and pointers references The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What are the differences between a pointer variable and a reference variable in C++?What is a smart pointer and when should I use one?Sort a Map<Key, Value> by valuesPointer of array of pointers that point to structuresJNA arrays and Pointerhow to get JNA read back function's string resultdeclaration of reference and pointer in c++Why should I use a pointer rather than the object itself?

Is it possible to create a QR code using text?

How dangerous is XSS

Is a distribution that is normal, but highly skewed, considered Gaussian?

What steps are necessary to read a Modern SSD in Medieval Europe?

Identify and count spells (Distinctive events within each group)

Mathematica command that allows it to read my intentions

Car headlights in a world without electricity

Gauss' Posthumous Publications?

Why can't we say "I have been having a dog"?

Finitely generated matrix groups whose eigenvalues are all algebraic

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Ising model simulation

Is it a bad idea to plug the other end of ESD strap to wall ground?

That's an odd coin - I wonder why

Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?

A hang glider, sudden unexpected lift to 25,000 feet altitude, what could do this?

Are British MPs missing the point, with these 'Indicative Votes'?

Does the Idaho Potato Commission associate potato skins with healthy eating?

What is the difference between 'contrib' and 'non-free' packages repositories?

Is it correct to say moon starry nights?

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

Can a PhD from a non-TU9 German university become a professor in a TU9 university?

How can the PCs determine if an item is a phylactery?

Is a linearly independent set whose span is dense a Schauder basis?



JNA, Mapping and pointers references



The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?What are the differences between a pointer variable and a reference variable in C++?What is a smart pointer and when should I use one?Sort a Map<Key, Value> by valuesPointer of array of pointers that point to structuresJNA arrays and Pointerhow to get JNA read back function's string resultdeclaration of reference and pointer in c++Why should I use a pointer rather than the object itself?










1















I need to use DLL inside my Java application. DLL is exporting some set of functions, authors called it "Direct DLL API". I'm trying to define in java equivalent of following function declaration:



int XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, DWORD* pdwCompressedSize, BOOL bEndOfData );


Inside my interface that extends Library I declared it as follows:



int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Pointer[] ppcCompressed, IntByReference pdwCompressedSize, boolean bEndOfData);


Problem is everytime I get an error:




Exception in thread "main" java.lang.Error: Invalid memory access




So basically I'm stuck at this point.



HXCEEDCMP hComp - is suppose to store handler to the function, and works fine as WString for init DLL / destroying DLL functions so I kept it like this.



The header reference "creature" is:



typedef HXCEEDCMP ( XCD_WINAPI *LPFNXCCREATEXCEEDCOMPRESSIONW )( const WCHAR* );


const BYTE* pcSource - is the source data for compression, inside my code I instantiate it this way:



private static Pointer setByteArrayPointer(String dataToCompress) 
Pointer pointer = new Memory(1024);
pointer.write(0, dataToCompress.getBytes(), 0,
dataToCompress.getBytes().length);

return pointer;



DWORD dwSourceSize - for this im getting reserved Memory size in this way:



String testData = "ABCDABCDABCDAAD";
Pointer source = setByteArrayPointer(testData);

(int) ((Memory)source).size()


BYTE** ppcCompressed - function should populate ppcCompressed reference after work is done. I assume I made a mistake there, by doing it in this way:



Pointer[] compressed = new Pointer(1024), new Pointer(1024);


DWORD* pdwCompressedSize - returned by function size of compressed data. I map it in this way:



IntByReference intByReference = new IntByReference();


Not sure if it is good idea aswell..



BOOL bEndOfData - i need to set it to true.



So finally my method call, which returns an error looks like this:



xceedApiDll.XcCompress(handle, source, (int) ((Memory)source).size(), compressed, intByReference, true);


Any help will be appreciated. Thank you.










share|improve this question






















  • I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

    – Daniel Widdis
    Mar 9 at 4:40












  • Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

    – soncrash
    Mar 9 at 9:47












  • The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

    – cubrr
    Mar 9 at 22:45











  • The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

    – cubrr
    Mar 9 at 22:48












  • @cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

    – soncrash
    Mar 10 at 8:25
















1















I need to use DLL inside my Java application. DLL is exporting some set of functions, authors called it "Direct DLL API". I'm trying to define in java equivalent of following function declaration:



int XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, DWORD* pdwCompressedSize, BOOL bEndOfData );


Inside my interface that extends Library I declared it as follows:



int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Pointer[] ppcCompressed, IntByReference pdwCompressedSize, boolean bEndOfData);


Problem is everytime I get an error:




Exception in thread "main" java.lang.Error: Invalid memory access




So basically I'm stuck at this point.



HXCEEDCMP hComp - is suppose to store handler to the function, and works fine as WString for init DLL / destroying DLL functions so I kept it like this.



The header reference "creature" is:



typedef HXCEEDCMP ( XCD_WINAPI *LPFNXCCREATEXCEEDCOMPRESSIONW )( const WCHAR* );


const BYTE* pcSource - is the source data for compression, inside my code I instantiate it this way:



private static Pointer setByteArrayPointer(String dataToCompress) 
Pointer pointer = new Memory(1024);
pointer.write(0, dataToCompress.getBytes(), 0,
dataToCompress.getBytes().length);

return pointer;



DWORD dwSourceSize - for this im getting reserved Memory size in this way:



String testData = "ABCDABCDABCDAAD";
Pointer source = setByteArrayPointer(testData);

(int) ((Memory)source).size()


BYTE** ppcCompressed - function should populate ppcCompressed reference after work is done. I assume I made a mistake there, by doing it in this way:



Pointer[] compressed = new Pointer(1024), new Pointer(1024);


DWORD* pdwCompressedSize - returned by function size of compressed data. I map it in this way:



IntByReference intByReference = new IntByReference();


Not sure if it is good idea aswell..



BOOL bEndOfData - i need to set it to true.



So finally my method call, which returns an error looks like this:



xceedApiDll.XcCompress(handle, source, (int) ((Memory)source).size(), compressed, intByReference, true);


Any help will be appreciated. Thank you.










share|improve this question






















  • I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

    – Daniel Widdis
    Mar 9 at 4:40












  • Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

    – soncrash
    Mar 9 at 9:47












  • The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

    – cubrr
    Mar 9 at 22:45











  • The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

    – cubrr
    Mar 9 at 22:48












  • @cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

    – soncrash
    Mar 10 at 8:25














1












1








1








I need to use DLL inside my Java application. DLL is exporting some set of functions, authors called it "Direct DLL API". I'm trying to define in java equivalent of following function declaration:



int XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, DWORD* pdwCompressedSize, BOOL bEndOfData );


Inside my interface that extends Library I declared it as follows:



int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Pointer[] ppcCompressed, IntByReference pdwCompressedSize, boolean bEndOfData);


Problem is everytime I get an error:




Exception in thread "main" java.lang.Error: Invalid memory access




So basically I'm stuck at this point.



HXCEEDCMP hComp - is suppose to store handler to the function, and works fine as WString for init DLL / destroying DLL functions so I kept it like this.



The header reference "creature" is:



typedef HXCEEDCMP ( XCD_WINAPI *LPFNXCCREATEXCEEDCOMPRESSIONW )( const WCHAR* );


const BYTE* pcSource - is the source data for compression, inside my code I instantiate it this way:



private static Pointer setByteArrayPointer(String dataToCompress) 
Pointer pointer = new Memory(1024);
pointer.write(0, dataToCompress.getBytes(), 0,
dataToCompress.getBytes().length);

return pointer;



DWORD dwSourceSize - for this im getting reserved Memory size in this way:



String testData = "ABCDABCDABCDAAD";
Pointer source = setByteArrayPointer(testData);

(int) ((Memory)source).size()


BYTE** ppcCompressed - function should populate ppcCompressed reference after work is done. I assume I made a mistake there, by doing it in this way:



Pointer[] compressed = new Pointer(1024), new Pointer(1024);


DWORD* pdwCompressedSize - returned by function size of compressed data. I map it in this way:



IntByReference intByReference = new IntByReference();


Not sure if it is good idea aswell..



BOOL bEndOfData - i need to set it to true.



So finally my method call, which returns an error looks like this:



xceedApiDll.XcCompress(handle, source, (int) ((Memory)source).size(), compressed, intByReference, true);


Any help will be appreciated. Thank you.










share|improve this question














I need to use DLL inside my Java application. DLL is exporting some set of functions, authors called it "Direct DLL API". I'm trying to define in java equivalent of following function declaration:



int XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, DWORD* pdwCompressedSize, BOOL bEndOfData );


Inside my interface that extends Library I declared it as follows:



int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Pointer[] ppcCompressed, IntByReference pdwCompressedSize, boolean bEndOfData);


Problem is everytime I get an error:




Exception in thread "main" java.lang.Error: Invalid memory access




So basically I'm stuck at this point.



HXCEEDCMP hComp - is suppose to store handler to the function, and works fine as WString for init DLL / destroying DLL functions so I kept it like this.



The header reference "creature" is:



typedef HXCEEDCMP ( XCD_WINAPI *LPFNXCCREATEXCEEDCOMPRESSIONW )( const WCHAR* );


const BYTE* pcSource - is the source data for compression, inside my code I instantiate it this way:



private static Pointer setByteArrayPointer(String dataToCompress) 
Pointer pointer = new Memory(1024);
pointer.write(0, dataToCompress.getBytes(), 0,
dataToCompress.getBytes().length);

return pointer;



DWORD dwSourceSize - for this im getting reserved Memory size in this way:



String testData = "ABCDABCDABCDAAD";
Pointer source = setByteArrayPointer(testData);

(int) ((Memory)source).size()


BYTE** ppcCompressed - function should populate ppcCompressed reference after work is done. I assume I made a mistake there, by doing it in this way:



Pointer[] compressed = new Pointer(1024), new Pointer(1024);


DWORD* pdwCompressedSize - returned by function size of compressed data. I map it in this way:



IntByReference intByReference = new IntByReference();


Not sure if it is good idea aswell..



BOOL bEndOfData - i need to set it to true.



So finally my method call, which returns an error looks like this:



xceedApiDll.XcCompress(handle, source, (int) ((Memory)source).size(), compressed, intByReference, true);


Any help will be appreciated. Thank you.







java api pointers dll jna






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 19:25









soncrashsoncrash

216




216












  • I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

    – Daniel Widdis
    Mar 9 at 4:40












  • Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

    – soncrash
    Mar 9 at 9:47












  • The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

    – cubrr
    Mar 9 at 22:45











  • The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

    – cubrr
    Mar 9 at 22:48












  • @cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

    – soncrash
    Mar 10 at 8:25


















  • I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

    – Daniel Widdis
    Mar 9 at 4:40












  • Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

    – soncrash
    Mar 9 at 9:47












  • The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

    – cubrr
    Mar 9 at 22:45











  • The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

    – cubrr
    Mar 9 at 22:48












  • @cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

    – soncrash
    Mar 10 at 8:25

















I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

– Daniel Widdis
Mar 9 at 4:40






I think the main problem is your use of Pointer(1024) for the compressed value. Use Memory(1024) to allocate native memory. Also BOOL in Windows maps to int. Any nonzero value is true.

– Daniel Widdis
Mar 9 at 4:40














Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

– soncrash
Mar 9 at 9:47






Using Memory as array return exception at runtime java.lang.IllegalArgumentException: Unsupported array argument type: class com.sun.jna.Memory, looks like Memory cannot be used as an array. I used single object instead and mapped BOOL to int so my final method declaration looks as follow: int XcCompress(WString hComp, Pointer pcSource, int dwSourceSize, Memory ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData); I got still the same error :(

– soncrash
Mar 9 at 9:47














The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

– cubrr
Mar 9 at 22:45





The docs say that you need to initialize a handle to the XceedZip object first. This is the pointer that you must pass as the HXCEEDCMP argument: xceed.com/wp-content/documentation/xceed-zip-for-activex/…

– cubrr
Mar 9 at 22:45













The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

– cubrr
Mar 9 at 22:48






The ppcCompressed argument may just be a pointer to the memory block to which the compressed data is written to, i.e. new PointerByReference(memory)

– cubrr
Mar 9 at 22:48














@cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

– soncrash
Mar 10 at 8:25






@cubrr I was reading the docs and I initialized a handle, but I didn't show this inside code. HXCEEDCMP is a WString inside my Java code, despite that it works correctly for XcDestroyXceedCompression it is causing problems after passing it to XcCompression method. For quick test I passed null reference to XcCompress hComp and I dont have Invalid memory access no more. However I'm not sure if data returned by XcCompress / XcDecompress method is correct, looks like I'm getting some random values now.. I try to declare HXCEEDCMP as Pointer, and I agree with PointerByReference

– soncrash
Mar 10 at 8:25













1 Answer
1






active

oldest

votes


















1














I think i solved the issue (thanks for comments guys). Maybe for someone using this library it will be useful:



In the end the main problem was with handler declaration and the ppcCompressed value.



I used the following solution which works fine for me:



Method declarations inside java interface:



int XcCompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData);
int XcUncompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcUncompressed, IntByReference pdwUncompressedSize, int bEndOfdata);


Usage:



private static final XceedFunctions XCEED_DLL_API;

static
XCEED_DLL_API = Native.load("XceedZipX64", XceedFunctions.class);


private static final String TEST_DATA = "abcabcddd";

//Data pointers
private static Pointer compHandle;
private static byte[] baSource = TEST_DATA.getBytes();
private static PointerByReference pbrCompressed = new PointerByReference();
private static PointerByReference pbrUncompressed = new PointerByReference();
private static IntByReference ibrCompressedSize = new IntByReference();
private static IntByReference ibrUncompressedSize = new IntByReference();

public static void main(String[] args)
try
boolean isSuccessfulInit = XCEED_DLL_API.XceedZipInitDLL();
if(isSuccessfulInit)
compHandle = XCEED_DLL_API.XcCreateXceedCompressionW(new WString("YOUR_LICENCE_KEY_HERE"));
int compressionResult = XCEED_DLL_API.XcCompress(compHandle, baSource, baSource.length, pbrCompressed, ibrCompressedSize, 1);
byte[] compressed = getDataFromPbr(pbrCompressed, ibrCompressedSize);
System.out.println("Compression result: " + compressionResult + " Data: " + new String(compressed));
int decompressionResult = XCEED_DLL_API.XcUncompress(compHandle, compressed, compressed.length, pbrUncompressed, ibrUncompressedSize, 1);
byte[] uncompressed = getDataFromPbr(pbrUncompressed, ibrUncompressedSize);
System.out.println("Decompression result: " + decompressionResult + " Data: " + new String(uncompressed));

finally
System.out.println("Free memory and shutdown");
if(compHandle != null)
XCEED_DLL_API.XcDestroyXceedCompression(compHandle);

XCEED_DLL_API.XceedZipShutdownDLL();



private static byte[] getDataFromPbr(PointerByReference pbr, IntByReference ibr)
return pbr.getValue().getByteArray(0, ibr.getValue());



Example output:




Compression result: 0 Data: KLJNLJNII yK



Decompression result: 0 Data: abcabcddd



Free memory and shutdown







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069736%2fjna-mapping-and-pointers-references%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I think i solved the issue (thanks for comments guys). Maybe for someone using this library it will be useful:



    In the end the main problem was with handler declaration and the ppcCompressed value.



    I used the following solution which works fine for me:



    Method declarations inside java interface:



    int XcCompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData);
    int XcUncompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcUncompressed, IntByReference pdwUncompressedSize, int bEndOfdata);


    Usage:



    private static final XceedFunctions XCEED_DLL_API;

    static
    XCEED_DLL_API = Native.load("XceedZipX64", XceedFunctions.class);


    private static final String TEST_DATA = "abcabcddd";

    //Data pointers
    private static Pointer compHandle;
    private static byte[] baSource = TEST_DATA.getBytes();
    private static PointerByReference pbrCompressed = new PointerByReference();
    private static PointerByReference pbrUncompressed = new PointerByReference();
    private static IntByReference ibrCompressedSize = new IntByReference();
    private static IntByReference ibrUncompressedSize = new IntByReference();

    public static void main(String[] args)
    try
    boolean isSuccessfulInit = XCEED_DLL_API.XceedZipInitDLL();
    if(isSuccessfulInit)
    compHandle = XCEED_DLL_API.XcCreateXceedCompressionW(new WString("YOUR_LICENCE_KEY_HERE"));
    int compressionResult = XCEED_DLL_API.XcCompress(compHandle, baSource, baSource.length, pbrCompressed, ibrCompressedSize, 1);
    byte[] compressed = getDataFromPbr(pbrCompressed, ibrCompressedSize);
    System.out.println("Compression result: " + compressionResult + " Data: " + new String(compressed));
    int decompressionResult = XCEED_DLL_API.XcUncompress(compHandle, compressed, compressed.length, pbrUncompressed, ibrUncompressedSize, 1);
    byte[] uncompressed = getDataFromPbr(pbrUncompressed, ibrUncompressedSize);
    System.out.println("Decompression result: " + decompressionResult + " Data: " + new String(uncompressed));

    finally
    System.out.println("Free memory and shutdown");
    if(compHandle != null)
    XCEED_DLL_API.XcDestroyXceedCompression(compHandle);

    XCEED_DLL_API.XceedZipShutdownDLL();



    private static byte[] getDataFromPbr(PointerByReference pbr, IntByReference ibr)
    return pbr.getValue().getByteArray(0, ibr.getValue());



    Example output:




    Compression result: 0 Data: KLJNLJNII yK



    Decompression result: 0 Data: abcabcddd



    Free memory and shutdown







    share|improve this answer



























      1














      I think i solved the issue (thanks for comments guys). Maybe for someone using this library it will be useful:



      In the end the main problem was with handler declaration and the ppcCompressed value.



      I used the following solution which works fine for me:



      Method declarations inside java interface:



      int XcCompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData);
      int XcUncompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcUncompressed, IntByReference pdwUncompressedSize, int bEndOfdata);


      Usage:



      private static final XceedFunctions XCEED_DLL_API;

      static
      XCEED_DLL_API = Native.load("XceedZipX64", XceedFunctions.class);


      private static final String TEST_DATA = "abcabcddd";

      //Data pointers
      private static Pointer compHandle;
      private static byte[] baSource = TEST_DATA.getBytes();
      private static PointerByReference pbrCompressed = new PointerByReference();
      private static PointerByReference pbrUncompressed = new PointerByReference();
      private static IntByReference ibrCompressedSize = new IntByReference();
      private static IntByReference ibrUncompressedSize = new IntByReference();

      public static void main(String[] args)
      try
      boolean isSuccessfulInit = XCEED_DLL_API.XceedZipInitDLL();
      if(isSuccessfulInit)
      compHandle = XCEED_DLL_API.XcCreateXceedCompressionW(new WString("YOUR_LICENCE_KEY_HERE"));
      int compressionResult = XCEED_DLL_API.XcCompress(compHandle, baSource, baSource.length, pbrCompressed, ibrCompressedSize, 1);
      byte[] compressed = getDataFromPbr(pbrCompressed, ibrCompressedSize);
      System.out.println("Compression result: " + compressionResult + " Data: " + new String(compressed));
      int decompressionResult = XCEED_DLL_API.XcUncompress(compHandle, compressed, compressed.length, pbrUncompressed, ibrUncompressedSize, 1);
      byte[] uncompressed = getDataFromPbr(pbrUncompressed, ibrUncompressedSize);
      System.out.println("Decompression result: " + decompressionResult + " Data: " + new String(uncompressed));

      finally
      System.out.println("Free memory and shutdown");
      if(compHandle != null)
      XCEED_DLL_API.XcDestroyXceedCompression(compHandle);

      XCEED_DLL_API.XceedZipShutdownDLL();



      private static byte[] getDataFromPbr(PointerByReference pbr, IntByReference ibr)
      return pbr.getValue().getByteArray(0, ibr.getValue());



      Example output:




      Compression result: 0 Data: KLJNLJNII yK



      Decompression result: 0 Data: abcabcddd



      Free memory and shutdown







      share|improve this answer

























        1












        1








        1







        I think i solved the issue (thanks for comments guys). Maybe for someone using this library it will be useful:



        In the end the main problem was with handler declaration and the ppcCompressed value.



        I used the following solution which works fine for me:



        Method declarations inside java interface:



        int XcCompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData);
        int XcUncompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcUncompressed, IntByReference pdwUncompressedSize, int bEndOfdata);


        Usage:



        private static final XceedFunctions XCEED_DLL_API;

        static
        XCEED_DLL_API = Native.load("XceedZipX64", XceedFunctions.class);


        private static final String TEST_DATA = "abcabcddd";

        //Data pointers
        private static Pointer compHandle;
        private static byte[] baSource = TEST_DATA.getBytes();
        private static PointerByReference pbrCompressed = new PointerByReference();
        private static PointerByReference pbrUncompressed = new PointerByReference();
        private static IntByReference ibrCompressedSize = new IntByReference();
        private static IntByReference ibrUncompressedSize = new IntByReference();

        public static void main(String[] args)
        try
        boolean isSuccessfulInit = XCEED_DLL_API.XceedZipInitDLL();
        if(isSuccessfulInit)
        compHandle = XCEED_DLL_API.XcCreateXceedCompressionW(new WString("YOUR_LICENCE_KEY_HERE"));
        int compressionResult = XCEED_DLL_API.XcCompress(compHandle, baSource, baSource.length, pbrCompressed, ibrCompressedSize, 1);
        byte[] compressed = getDataFromPbr(pbrCompressed, ibrCompressedSize);
        System.out.println("Compression result: " + compressionResult + " Data: " + new String(compressed));
        int decompressionResult = XCEED_DLL_API.XcUncompress(compHandle, compressed, compressed.length, pbrUncompressed, ibrUncompressedSize, 1);
        byte[] uncompressed = getDataFromPbr(pbrUncompressed, ibrUncompressedSize);
        System.out.println("Decompression result: " + decompressionResult + " Data: " + new String(uncompressed));

        finally
        System.out.println("Free memory and shutdown");
        if(compHandle != null)
        XCEED_DLL_API.XcDestroyXceedCompression(compHandle);

        XCEED_DLL_API.XceedZipShutdownDLL();



        private static byte[] getDataFromPbr(PointerByReference pbr, IntByReference ibr)
        return pbr.getValue().getByteArray(0, ibr.getValue());



        Example output:




        Compression result: 0 Data: KLJNLJNII yK



        Decompression result: 0 Data: abcabcddd



        Free memory and shutdown







        share|improve this answer













        I think i solved the issue (thanks for comments guys). Maybe for someone using this library it will be useful:



        In the end the main problem was with handler declaration and the ppcCompressed value.



        I used the following solution which works fine for me:



        Method declarations inside java interface:



        int XcCompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcCompressed, IntByReference pdwCompressedSize, int bEndOfData);
        int XcUncompress(Pointer hComp, byte[] pcSource, int dwSourceSize, PointerByReference ppcUncompressed, IntByReference pdwUncompressedSize, int bEndOfdata);


        Usage:



        private static final XceedFunctions XCEED_DLL_API;

        static
        XCEED_DLL_API = Native.load("XceedZipX64", XceedFunctions.class);


        private static final String TEST_DATA = "abcabcddd";

        //Data pointers
        private static Pointer compHandle;
        private static byte[] baSource = TEST_DATA.getBytes();
        private static PointerByReference pbrCompressed = new PointerByReference();
        private static PointerByReference pbrUncompressed = new PointerByReference();
        private static IntByReference ibrCompressedSize = new IntByReference();
        private static IntByReference ibrUncompressedSize = new IntByReference();

        public static void main(String[] args)
        try
        boolean isSuccessfulInit = XCEED_DLL_API.XceedZipInitDLL();
        if(isSuccessfulInit)
        compHandle = XCEED_DLL_API.XcCreateXceedCompressionW(new WString("YOUR_LICENCE_KEY_HERE"));
        int compressionResult = XCEED_DLL_API.XcCompress(compHandle, baSource, baSource.length, pbrCompressed, ibrCompressedSize, 1);
        byte[] compressed = getDataFromPbr(pbrCompressed, ibrCompressedSize);
        System.out.println("Compression result: " + compressionResult + " Data: " + new String(compressed));
        int decompressionResult = XCEED_DLL_API.XcUncompress(compHandle, compressed, compressed.length, pbrUncompressed, ibrUncompressedSize, 1);
        byte[] uncompressed = getDataFromPbr(pbrUncompressed, ibrUncompressedSize);
        System.out.println("Decompression result: " + decompressionResult + " Data: " + new String(uncompressed));

        finally
        System.out.println("Free memory and shutdown");
        if(compHandle != null)
        XCEED_DLL_API.XcDestroyXceedCompression(compHandle);

        XCEED_DLL_API.XceedZipShutdownDLL();



        private static byte[] getDataFromPbr(PointerByReference pbr, IntByReference ibr)
        return pbr.getValue().getByteArray(0, ibr.getValue());



        Example output:




        Compression result: 0 Data: KLJNLJNII yK



        Decompression result: 0 Data: abcabcddd



        Free memory and shutdown








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 10 at 10:15









        soncrashsoncrash

        216




        216





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069736%2fjna-mapping-and-pointers-references%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme