Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:56:08+00:00 2026-06-12T01:56:08+00:00

I’m using JNA to call into a C library from Java. In my C

  • 0

I’m using JNA to call into a C library from Java.

In my C code I have:

   void printStructArray( SomeStruct **someStruct, int arraySize );

This expects an array of pointers to struct, ie the method does this:

void printStructArray( SomeStruct **someStruct, int arraySize ) {
   for( int i = 0; i < arraySize; i++ ) {
      cout << "someStruct: " << someStruct[i]->aLong << " " << someStruct[i]->aString << " " << someStruct[i]->aDouble << endl;
   }
}

It’s just a toy example, but I have an actual library I want to talk to which needs the same type of argument, but I think using a toy example is easier to explain here?

I’ve tried all sorts of things, but I’m not sure how to (i) declare this function in JNA (ii) call this function in JNA.

My latest (failed) attempt is:

SomeStruct.byReference[] structs = new SomeStruct.byReference[]{
        new SomeStruct.byReference(123,"hey!",1.23),
        new SomeStruct.byReference(456,"cool!",1.45),
        new SomeStruct.byReference(789,"world!",1.67) };
PointerByReference pointerByReference = new PointerByReference(structs[0].getPointer());
JniTest.instance.printStructArray(pointerByReference, 3);

This causes a SIGSEGV.

Alternatively:

SomeStruct.byReference[] structs = (SomeStruct.byReference[]) new SomeStruct().toArray( new SomeStruct.byReference[]{
        new SomeStruct.byReference(123,"hey!",1.23),
        new SomeStruct.byReference(456,"cool!",1.45),
        new SomeStruct.byReference(789,"world!",1.67) } );
PointerByReference pointerByReference = new PointerByReference(structs[0].getPointer());
JniTest.instance.printStructArray(pointerByReference, 3);

This causes an ArrayStoreException

Tried this also:

SomeStruct.byReference[] structs = new SomeStruct.byReference[]{
    new SomeStruct.byReference(123,"hey!",1.23),
    new SomeStruct.byReference(456,"cool!",1.45),
    new SomeStruct.byReference(789,"world!",1.67) };    JniTest.instance.printStructArray(structs, 3);

With method declared as:

void printStructArray(SomeStruct.byReference[] someStructarray, int num);

This gives ‘0’ as the output from the function, although the good point is it doesn’t crash, but it’s not giving correct behavior either.

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:56:09+00:00Added an answer on June 12, 2026 at 1:56 am

    In the end, I never found a working solution to this. What I did was workaround by writing a wrapper interface, in C, which presented a very simple interface to Java, which was then very easy to link to using JNA, without needing Pointer and so on. This worked quite well, and was less effort than trying to get Pointer working.

    So, my interface looked something like:

    int createHandle()
    void doSomething( int handle )
    void releaseHandle( int handle)
    

    It seemed to take a lot less effort to get this working, in terms of time, than trying to create some super complicated jna implementation to directly connect to the underlying c interface.

    The other advantage is this meant it was easy to connect to a c++ library, since this way, the c++ interface is wrapped by a c interface, which is easy to connect to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.